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();

?>

 

posted on 2021-04-01 18:41  totau  阅读(19)  评论(0编辑  收藏  举报

导航