标签:The utc bubuko 访问权限 有一个 UNC efi ati 使用
一,概念:
定义一个算法中的操作框架,而将一些步骤延迟到子类中。使得子类可以不改变算法的结构即可重定义该算法的某些特定步骤。(Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm‘s structure)
二,类图
AbstractClass叫做抽象模板,它的方法分为两类:
三,代码实例
class Car { func drive() -> Void{ self.startEngine() self.hungUpGear() self.loosenTheClutch() } func startEngine() { print("start the engine.") } func hungUpGear() { print("Hung up the gear.") } func loosenTheClutch() { print("Loosen the clutch, go.") } } class BMW: Car { override func startEngine() { print("start v8 engine.") } override func hungUpGear() { print("On the brake pedal, then hung up the gear.") } override func loosenTheClutch() { print("Brake pedal up, go.") } } class BYD: Car { override func startEngine() { print("start engine.eng~ ") } override func hungUpGear() { print("On the clutch, then hung up the gear.") } }
使用
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let car = BMW() car.drive() } }
标签:The utc bubuko 访问权限 有一个 UNC efi ati 使用
原文地址:https://www.cnblogs.com/yangzigege/p/8970714.html