abstract class EmployeeType{
private static $_a = 1;
private static $_b = 2;
private static $_c = 3;
private static $_d = 4;
public static function getType($type = null){
switch ($type){
case self::$_a:
return new A();
break;
case self::$_b:
return new B();
break;
case self::$_c:
return new C();
break;
case self::$_d:
return new D();
break;
default :
return null;
}
}
abstract function payAcount();
}
class A extends EmployeeType{
public function payAcount(){
return 111;
}
}
class B extends EmployeeType{
public function payAcount() {
return 222;
}
}
class C extends EmployeeType{
public function payAcount(){
return 333;
}
}
class D extends EmployeeType{
public function payAcount(){
return 'ddddd';
}
}
class Employee{
private $_type;
function __construct($type){
$this->_type = EmployeeType::getType($type);
}
public function setType($type){
$this->_type = EmployeeType::getType($type);
}
public function payAcount(){
return empty($this->_type) ? 'this not a object' : $this->_type->payAcount();
}
}
$employeeObj = new Employee(33);
echo $employeeObj->payAcount();