Delegates.observable追踪观察可变数据更新,Kotlin
import kotlin.properties.Delegates
import kotlin.reflect.KProperty
class Person {
var name: String by Delegates.observable("fly") { prop: KProperty<*>, old: String, new: String ->
println("$old -> $new")
}
}
fun main() {
val p = Person()
p.name = "phil"
}
fly -> phil
Java设计模式:观察者模式_zhangphil的博客-CSDN博客import java.util.ArrayList;public abstract class Observable {private ArrayList observers = new ArrayList();public void addObserver(Observer observer) {observers.add(observer...https://blog.csdn.net/zhangphil/article/details/88738556不定长函参的Java观察者模式更新数据传递_zhangphil的博客-CSDN博客不定长函参的Java观察者模式更新数据传递import java.util.LinkedList;/** * 抽象被观察者。 * * @param */public abstract class Subject { private LinkedList observers; publ...
https://blog.csdn.net/zhangphil/article/details/101872234Java观察者模式 : Observer / Observable_zhangphil的博客-CSDN博客/**Java观察者模式的场景:一个女孩洗澡,被很多男孩偷看。女孩洞察后,搜索坏男孩,然后继续洗澡。三个类:Boy,Girl还有主类MainClass。*//*男孩Boy.java*/import java.util.Observable;import java.util.Observer;public class Boy implements Observer{...
https://blog.csdn.net/zhangphil/article/details/43767395