鬆耦合 設計
鬆耦合 設計
鬆耦合 設計
鬆耦合 設計
public abstract class Command
{
protected Barbecuer receiver;
public Command(Barbecuer receiver)
{
this.receiver = receiver;
}
abstract public void ExcuteCommand();
}
class BakeMuttonCommand : Command
{
public BakeMuttonCommand(Barbecuer receiver) : base(receiver)
{
}
public override void ExcuteCommand()
{
receiver.BakeMutton();
}
}
class BakeChickenWingCommand : Command
{
public BakeChickenWingCommand(Barbecuer receiver) : base(receiver)
{
}
public override void ExcuteCommand()
{
receiver.BakeChickenWing();
}
}
public class Waiter
{
private Command command;
public void SetOrder(Command command)
{
this.command = command;
}
public void Notify()
{
command.ExcuteCommand();
}
}
以上設計仍有真實情況不敷使用的案例,一次點餐取代多次點餐。
紀錄多少Order,以備收費和統計,中途取消Order…問題。
將在下一版鬆耦合解決。