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
posted @ 2018-08-16 10:10  不一样的开始  阅读(93)  评论(0编辑  收藏  举报