abstract class Department {
public abstract function createEmployee($id);
public function fire($id) {
$employee = $this->createEmployee($id);
$employee->paySalary();
$employee->dismiss();
}
}
class ITDepartment extends Department {
public function createEmployee($id) {
return new Programmer($id);
}
}
class AccountingDepartment extends Department {
public function createEmployee($id) {
return new Accountant($id);
}
}