/*
大宏药业的制药机器有2个按钮,按钮A、按钮B。
机械操作员不需要知道具体的机械操作原理、只需要透过机器界面操作按钮。
机器有2个功能:包装药品、出货药品
把操作发送者和执行接受者的控件解耦、当新增功能、更改操作界面更容易。
*/
protocol Operation {
func operate()
}
class Wrap : Operation {
func operate() {
print("Wrap product.")
}
}
class Ship : Operation {
func operate() {
print("Ship product.")
}
}
class Equipment {
var p_stEquipmentName : String = ""
var p_stMedicine : String = ""
var p_mMedicNumber : Int = 0
init(p_stInputEquipmentName : String) {
p_stEquipmentName = p_stInputEquipmentName
}
func setEquipment(p_stInputEquipmentName : String) {
p_stEquipmentName = p_stInputEquipmentName
}
func getEquipment() -> String {
return p_stEquipmentName
}
func OperationMachine(p_obOperateCommand : Operation) {
p_obOperateCommand.operate()
}
}
var p_obWrapProduct = Wrap()
var p_obShipProduct = Ship()
var p_obEquipment = Equipment(p_stInputEquipmentName: "MedicineMachine")
p_obEquipment.OperationMachine(p_obOperateCommand: p_obWrapProduct)
p_obEquipment.OperationMachine(p_obOperateCommand: p_obShipProduct)
/*
Wrap product.
Ship product.
*/
留言列表