【读书笔记-重构与模式】 抽象工厂与单例模式的组合使用

来源:互联网 发布:日语n1网络课程 编辑:程序博客网 时间:2024/05/16 06:42

《深入PHP面向对象模式与实践》:

   抽象工厂与单例模式的结合使用时十分普遍的。


require_once('setting.php');class AppConfig{     private static $instance = NULL;     private $commsManager;     private function __construct(){         $this->init();     }     private function init(){         switch(Settings::$COMMSTYPE{                           case 'Mega':                 $this->commsManager = new MegaCommsManager;break;             default:                 $this->commsManager = new BloggsCommsManager;break;             }     }     public static function getInstance(){         if(empty(self::$instance)){            self::$instance = new self;         }         return self::$instance;     }     public function getCommsMananger(){         return  $this->commsManager;     }}


原创粉丝点击