
you are here
225
6
章
Command
パターン
public class MacroCommand implements Command {
Command[] commands;
public MacroCommand(Command[] commands) {
this.commands = commands;
}
public void execute() {
for (int i = 0; i < commands.length; i++) {
commands[i].execute();
}
}
}
リモコンにはパーティモードが必要!
Hottub
on()
off()
circulate()
jetsOn()
jetsOff()
setTemperature()
Stereo
on()
off()
setCd()
setDvd()
setRadio()
setVolume()
Light
on()
off()
dim()
on()
off()
setInputChannel()
setVolume()
TV
メアリーのアイデアは、他のコ
マンドを実行できる新しい種類
のコマンドを作成することです。
しかも、他の複数のコマンドを
実行できるものです!
素晴らし
いアイデアだと思いませんか?
コマンドの配列を引数に取り、その配列を
MacroCommand
に保存します。
リモコンがこのマクロを実行すると、配列のコマン
ドを
1
つずつ実行します。
ボタン1 つ押すだけで、照明を薄暗くし、オーディオとテ
レビの電源を入れ、お風呂を沸かし始めることができなけ ...