Loading

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 语句很相似.自行领悟

 

下面来个实例代码:

 

posted @ 2019-08-02 17:11  mingBolg  阅读(90)  评论(0编辑  收藏  举报