Exemplo n.º 1
0
println();
$control1 = new RemoteControl();
#电灯
$light1 = new Light1();
$light_on_command = new LightOnCommand1($light1);
$light_off_command = new LightOffCommand1($light1);
#音响
$steteo = new Stereo();
$steteo_on_command = new StereoOnCommand($steteo);
$stereo_off_command = new StereoOffCommand($steteo);
#设置插槽控制xx
$control1->setCommand(0, $light_on_command, $light_off_command);
$control1->setCommand(1, $steteo_on_command, $stereo_off_command);
echo $control1;
$control1->bottonOnWasPressed(0);
$control1->bottonOffWasPressed(0);
echo $control1;
println('undo botton was pressed');
$control1->bottonUndoWasPressed();
#开音响
$control1->bottonOnWasPressed(1);
echo $control1;
println('undo botton was pressed');
#把音响关了
$control1->bottonUndoWasPressed();
println(SEPARATE, 'END', SEPARATE);
/**
* 输出:
 ------------------------------Remote Control--------------------------------
 [slot 0] headfist.command.remote.LightOnCommand1        headfist.command.remote.LightOffCommand1
 [slot 1] headfist.command.remote.StereoOnCommand        headfist.command.remote.StereoOffCommand