Swift 10 组合模式 Composite Pattern
来源:互联网 发布:互联网金融网络平台 编辑:程序博客网 时间:2024/06/05 19:10
/*大宏药业有阿司匹林和扑热息痛生产部门。对於老板、他只需要指示生产药品就行。组合模式能各控件解耦、假如想增加抗组胺药生产部门、只需增加此部门即可。*/class MedicineProduct {func addOrder(p_obMedicOrder : MedicineProduct) { }func removeOrder(p_mOrderNum : Int) { }func getOrder(p_mOrderNum : Int) -> MedicineProduct { return MedicineProduct()}func produceMedic() { }}class Aspirin : MedicineProduct {var p_stMedicBrand : String = ""init(p_stInputMedicBrand : String) {p_stMedicBrand = p_stInputMedicBrand}override func addOrder(p_obMedicOrder : MedicineProduct) {print("You have no authority to add order")}override func removeOrder(p_mOrderNum : Int) {print("You have no authority to remove order")}override func getOrder(p_mOrderNum : Int) -> MedicineProduct {print("You have no authority to get order")return MedicineProduct()}override func produceMedic() {print("Produce \(p_stMedicBrand) aspirin")}}class Pharmacology : MedicineProduct {var p_stMedicBrand : String = ""init(p_stInputMedicBrand : String) {p_stMedicBrand = p_stInputMedicBrand}override func addOrder(p_obMedicOrder : MedicineProduct) {print("You have no authority to add order")}override func removeOrder(p_mOrderNum : Int) {print("You have no authority to remove order")}override func getOrder(p_mOrderNum : Int) -> MedicineProduct {print("You have no authority to get order")return MedicineProduct()}override func produceMedic() {print("Produce \(p_stMedicBrand) Pharmacology")}}class MedicineOffice : MedicineProduct {var p_arrMedicProduct : [MedicineProduct] = []var p_stMedicOfficName : String = ""func setMedicOfficName(p_stInputMedicOfficName : String) {p_stMedicOfficName = p_stInputMedicOfficName}override func addOrder(p_obMedicOrder : MedicineProduct) {p_arrMedicProduct.append(p_obMedicOrder)}override func removeOrder(p_mOrderNum : Int) {p_arrMedicProduct.remove(at : p_mOrderNum)print("remove \(p_mOrderNum) order")}override func getOrder(p_mOrderNum : Int) -> MedicineProduct {return p_arrMedicProduct[p_mOrderNum]}override func produceMedic() {print("\(p_stMedicOfficName) produces Aspirin & Pharmacology")for p_obOrder in p_arrMedicProduct {p_obOrder.produceMedic()}}}let medicineOffice = MedicineOffice()medicineOffice.setMedicOfficName(p_stInputMedicOfficName : "Da Honge Medic Office")var Product1 = Aspirin(p_stInputMedicBrand : "ZhangXing")medicineOffice.addOrder(p_obMedicOrder : Product1)var Product2 = Pharmacology(p_stInputMedicBrand : "DaTong")medicineOffice.addOrder(p_obMedicOrder : Product2)medicineOffice.produceMedic()/*Da Honge Medic Office produces Aspirin & PharmacologyProduce ZhangXing aspirinProduce DaTong Pharmacology*/
0 0
- Swift 10 组合模式 Composite Pattern
- 组合模式-Composite Pattern
- Composite Pattern(组合模式)
- 【组合模式】Composite Pattern
- 组合模式 Composite Pattern
- 组合模式(Composite Pattern)
- 组合模式(Composite Pattern)
- 组合模式【Composite Pattern】
- 组合模式(Composite Pattern)
- composite pattern -- 组合模式
- 组合模式(Composite Pattern)
- 组合模式(Composite Pattern)
- Composite Pattern 组合模式
- 组合模式(Composite Pattern)
- 组合模式 (Composite Pattern)
- 组合模式【Composite Pattern】
- 组合模式【Composite Pattern】
- 组合模式 | Composite Pattern
- Swift 09 适配器模式 Adapter pattern
- 深度学习一
- HDU 1059 Dividing 多重背包 .
- kmp算法(字符串匹配)
- asynchttpclient的post方法发送json格式参数和表单格式参数
- Swift 10 组合模式 Composite Pattern
- 控制DIV的选取
- Angularjs 学习笔记(一)基础
- mysql之给字段设置缺省值
- nefu1121第k个序列(dfs)
- iOS swift-桥接OC的开源框架
- 图像格式RGB24转YUV422(YUYV)转换代码
- CountDownTimer倒计时按钮的实现
- 快速排序(升序)