php 工厂模式
<?php interface Inter{ public function show(); } class Test1 implements Inter{
public function show(){ echo "test1"; } } class Test2 implements Inter{
public function show(){ echo "test2"; } }class transFactory{ public static function factory($type) { switch ($type) { case 'test1': return new Test1(); break; case 'test2': return new Test2(); break; } } } $test=transFactory::factory('test1'); $test->show();
Inter