php工厂模式
核心代码:
<?php //工厂模式的实现 class Factory { public static function getInstance($className) { switch ($className) { case 'Re': return new Re(); break; case 'Square': return new Circle(); break; default: return '好的'; break; } } }
跟switch 语句很相似.自行领悟
下面来个实例代码: