小孩和公共设施
用继承的方法:
class Sanitation{ public function Washhands(){ echo "Cleaning!"; } } class Child extends Sanitation{ } $child=new Child(); $child->Washhands();
委托关系:
class Sanitation{ public function Washhands(){ echo "Cleaning!"; } } class Child { private $sanitation; function __construct(){ $this->sanitation=new Sanitation(); } public function Washhands(){ return $this->sanitation->Washhands(); } } $child=new Child(); $child->Washhands();
原文:http://www.cnblogs.com/canbefree/p/3835053.html