限制将类实例化到某个范围

时间:2013-03-06 15:54:06

标签: php oop design-patterns

我正在编写一个类,我想限制该类的用户仅在类型XXX的类中使用它。如何在PHP中完成此(朋友)功能? 与用户交谈不是一个可行的选择: - )

示例:

class ActionLog{
 ....
 ....
 ....
}

abstract class Controller{ ...}

class BabaController extends Controller{
    public function SuperAction(){
        $X = new ActionLog();; OK!!!
    }
}

class SomeOtherBabaWhichIsNotAController extends SomthingElse{
    public function super_nice_function(){
        $X = new ActionLog();//WILL CRASHHHH!!!!!!!!!!
    }
}

0 个答案:

没有答案