一些巧妙的实现
2016-01-19 本文已影响10人
两仪周
1.父类要求子类实现的方法,且在实现前后必须保证执行一定的逻辑
class Parent {
final func method() {
print("执行methodImpl前必须执行的过程 ....")
methodImpl()
print("执行methodImpl后必须执行的过程 .....")
}
func methodImpl() {
fatalError("子类必须实现的方法")
}
}
class Child: Parent {
override func methodImpl() {
print("子类的业务逻辑")
}
}