Ejemplo n.º 1
0
    {
        $this->cook->drink();
    }
}
class cookControl
{
    private $mealcommand;
    private $drinkcommand;
    public function addCommand(Command $mealcommand, Command $drinkcommand)
    {
        $this->mealcommand = $mealcommand;
        echo get_class($mealcommand);
        $this->drinkcommand = $drinkcommand;
    }
    public function callmeal()
    {
        $this->mealcommand->execute();
    }
    public function calldrink()
    {
        $this->drinkcommand->execute();
    }
}
$controller = new cookControl();
$cook = new cook();
$mealcommand = new MealCommand($cook);
$drinkcommand = new DrinkCommand($cook);
$controller->addCommand($mealcommand, $drinkcommand);
$controller->callmeal();
$controller->calldrink();
Ejemplo n.º 2
0
    {
        $this->cook->drink();
    }
}
class cookControl
{
    private $mealcommand;
    private $drinkcommand;
    // 将命令发送者绑定到命令接收器上面来
    public function addCommand(Command $mealcommand, Command $drinkcommand)
    {
        $this->mealcommand = $mealcommand;
        $this->drinkcommand = $drinkcommand;
    }
    public function callmeal()
    {
        $this->mealcommand->execute();
    }
    public function calldrink()
    {
        $this->drinkcommand->execute();
    }
}
$control = new cookControl();
$cook = new cook();
$mealcommand = new MealCommand($cook);
$drinkcommand = new DrinkCommand($cook);
$control->addCommand($mealcommand, $drinkcommand);
$control->callmeal();
$control->calldrink();