/**
用final关键字来防止重写
final,最后的,最终的;决定性的;不可更改的
final 修饰类的话,表示这个类不可以被继承。
*/
class Observer {
// final 加上
var storeProperty: Int = 0 {
willSet {
print("storeProperty father will Set")
}
didSet {
print("storeProperty father did Set")
}
}
// final
var computeProperty: Int {
get {
return 0
}
set {
print("Do nothing!")
}
}
//final
func dodododTest() -> Void {
print("dadadadadaddadaad")
}
}
class ChildOfObserver: Observer {
override var storeProperty: Int {
willSet {
print("storeProperty will Set")
}
didSet {
print("storeProperty did Set")
}
}
override var computeProperty: Int {
willSet {
print("computeProperty will Set")
}
didSet {
print("computeProperty did Set")
}
}
override func dodododTest() {
}
}
let co = ChildOfObserver.init()
co.storeProperty = 10