クラスのメソッドをカプセル化して、それらを消費するクラス内に公開することは可能かどうか疑問に思っています。例(JFTR、このコードが間違っていることは知っています)
class Consumer{
public function __construct($obj){
$this->obj = $obj;
}
public function doCommand(){
$this->obj->command();
}
}
class Consumed{
//I would make the constructor private, but to save space...
public function __construct(){}
private function command(){
echo "Executing command in the context of the Consumer";
}
}
$consumer = new Consumer(new Consumed);
$consumer->doCommand();
//just to reiterate, I know this throws an error
最終的には、単一の制御クラスのコンテキスト外で直接参照できないコンポーネントを作成できるようにしたいと考えています。