PHP设计模式-简单工厂模式

<?php
    
class american{
    public function talk(){
        echo ‘english‘;
    }
    public function skin(){
        echo ‘while‘;
    }
}
class chiness{
    public function talk(){
        echo ‘汉语汉语‘;
    }
    public function skin(){
        echo ‘黄色‘;
    }
}

class controll{
    public function anser($people){
        switch($people){
            case ‘chiness‘:
                return  new chiness();
            case ‘american‘:
                return new american();
            default:
                return null;
        }
    }
}


$obj = new controll();
$chiness = $obj->anser(‘chiness‘);
$chiness->talk();
$chiness->skin();

?>

 

PHP设计模式-简单工厂模式

上一篇:生成https证书


下一篇:asp.net mvc如何在单元测试中使用session