设计模式(二)工厂模式

工厂模式(Factor Pattern) 负责生成其他对象的类或方法

代码实现:

class DemoController extends APP_Controller_Action {

    public function factoryAction(){
        $name = $this->getParam("name");
        $action = $this->getParam("action");
        $child = factory::createClass($name);
        
    }
}

class factory{
     static function createClass($class_name){
         return new $class_name;
     }
}

class child{
    public function test(){
        echo "create child factor success";
    }
}

class adult{
    public function test(){
        echo "create adult factor success";
    }
}

  

posted @ 2017-04-20 20:10  玛吉  阅读(116)  评论(0编辑  收藏  举报