Quick actions

cmd+k|ctrl+k

Navigation

Languages

Паттерн "Команда"

Snippet info

Language

Php

Visibility

public

Author

dmitry8912

Created

2017-07-11T19:41:02Z

Updated

2017-07-11T19:43:43Z

<?php

interface ICommand
{
    function execute();
}

interface IActor
{
    function doAction();
}

class SomeShit implements IActor
{
    function __construct()
    {
        echo('SomeShit initiated!');
    }
    public function doAction()
    {
        echo('SomeShit do some shit!');
    }
}

class ShitCommand implements ICommand
{
    public $_actor;
    function __construct()
    {
        $this->_actor = new SomeShit();
    }
    public function execute()
    {
        $this->_actor->doAction();
    }
}

class Commander
{
    private $commands = array();
    
    function __construct()
    {
        $this->commands[]=new ShitCommand();
    }
    
    function doAll()
    {
        foreach($this->commands as $command)
        {
            $command->execute();
        }
    }
}

$c = new Commander();
$c->doAll();
INFO