Exemplo n.º 1
0
    }
    abstract function fire();
}
class Minion extends Employee
{
    function fire()
    {
        print "{$this->name}: убери со стола \n";
    }
}
class NastyBoss
{
    private $employees = [];
    function addEmployee($employees)
    {
        $this->employees[] = new Minion($employees);
    }
    function projectFails()
    {
        if (count($this->employees) > 0) {
            $emp = array_pop($this->employees);
            $emp->fire();
        }
    }
}
$boss = new NastyBoss();
$boss->addEmployee("Игорь");
$boss->addEmployee("Владимир");
$boss->addEmployee("Мария");
$boss->projectFails();
Exemplo n.º 2
0
    }
}
class WellConnected extends Employee
{
    function fire()
    {
        print "{$this->name}: blablabla\n";
    }
}
class NastyBoss
{
    private $employees = array();
    function addEmployee(Employee $employee)
    {
        $this->employees[] = $employee;
    }
    function projectFails()
    {
        if (count($this->employees) > 0) {
            $emp = array_pop($this->employees);
            $emp->fire();
        }
    }
}
$employee = new NastyBoss();
$employee->addEmployee(Employee::recruit('Slava'));
$employee->addEmployee(Employee::recruit('Lidia'));
$employee->addEmployee(Employee::recruit('Nestor'));
$employee->projectFails();
$employee->projectFails();
$employee->projectFails();