Head First設計模式C++實現-Command模式
定義:
命令模式將“請求”封裝成物件,以便試用不同的請求,佇列或者日誌來引數化其他物件。命令模式也可支援可撤銷的操作。
UML圖:
程式實現:
程式輸出:
----------- Remote Control ----------
[slot 0]LightOnCommand LightOffCommand
[slot 1]LightOnCommand LightOffCommand
[slot 2]CeillingFanOnCommand CeillingFanOffCommand
[slot 3]StereoOnWithCDCommand StereoOffCommand
[slot 4]NoCommand NoCommand
[slot 5]NoCommand NoCommand
[slot 6]NoCommand NoCommand
Living Roomlight is on
Living Roomlight is off
Kitchenlight is on
Kitchenlight is off
Living Room ceiling fan is on high
Living Room ceiling fan is off
Living Room Stereo volume set to 11
Living Room stereo is set for CD input
Living Room stereo is on
Living Room stereo is on
Living Room stereo is set for CD input
Living Room Stereo volume set to 11
Living Room stereo is off
請按任意鍵繼續. . .