工厂模式是另一种非常常用的模式,正如其名字所示:确实是对象实例的生产工厂。某些意义上,工厂模式提供了通用的方法有助于我们去获取对象,而不需要关心其具体的内在的实现。/** * Factory claa[工厂模式] */interface SystemFactory{ public function createSystem($type);}class MySystemFactory implements SystemFactory{ //实现工厂方法 public function createSystem($type) { // TODO: Implement createSystem() method. switch ($type) { case 'Mac': return new MacSystem(); case 'Win': return new WinSystem(); case 'Linux': return new LinuxSystem(); } }}class System{}class WinSystem extends System{}class MacSystem extends System{}class LinuxSystem extends System{}$System_obj = new MySystemFactory();var_dump($System_obj->createSystem('Mac'));
来源:https://www.cnblogs.com/caohongchang/p/11537501.html