Esempio n. 1
0
    {
        $this->_television = $device;
    }
    public function execute()
    {
        $this->_television->volumeDown();
    }
}
// let's try it all out
// our application will need some reveiver object
$device = new Television();
// our application will need an invoker object, which
// in turns relies on concrete command objects:
$on = new OnCommand($device);
// command to switch device on
$off = new OffCommand($device);
// command to switch device off
$up = new UpCommand($device);
// command to turn volume up
$down = new DownCommand($device);
// command to turn volume down
// now we are ready to create our invoker object which
// we should think of as some sort of application menu.
$menu = new RemoteControl($on, $off, $up, $down);
// client code is now able to access the invoker object
$menu->switchPowerOn();
$menu->raiseVolume();
$menu->raiseVolume();
$menu->raiseVolume();
$menu->lowerVolume();
$menu->switchPowerOff();