php 中的工厂方法

    // 工厂函数
    // 自动加载一个类
   class Example {
       public static function factory ($type) {
           if(include_once "./".$type.".php") {
               $classname = $type;
               return new $classname;
           } else {
               throw new Exception("file not find");
           }
       }
   }
   
   $x = Example::factory("classOne");
   $x->f();
    

 

posted @ 2013-03-16 10:43  刘牛德  阅读(151)  评论(0编辑  收藏  举报