這個設計模式,說真的,我還沒讀懂,讀懂的兄弟可以留言幫我解釋一下,我需要 慢慢的研究 這 中模式的好處,和優點,先附上我的代碼 看完之後,我凌亂了 ...
這個設計模式,說真的,我還沒讀懂,讀懂的兄弟可以留言幫我解釋一下,我需要 慢慢的研究 這 中模式的好處,和優點,先附上我的代碼
abstract class component{ abstract public function operation(); } class concreteComponent extends component { public function operation() { // TODO: Implement operation() method. echo '這裡是具體操作'; } } abstract class Decoratr extends component { protected $component; public function setComponent($component){ $this->component = $component; } public function operation() { // TODO: Implement operation() method. if($this->component!=null){ $this->component->operation(); } } } class A extends Decoratr { private $state; public function operation() { parent::operation(); // TODO: Change the autogenerated stub $this->state = 'new state'; echo '裝飾A'; } } class B extends Decoratr { public function operation() { parent::operation(); // TODO: Change the autogenerated stub $this->behavior(); echo '裝飾B'; } public function behavior(){ } } $c = new concreteComponent(); $a = new A(); $b = new B(); $a->setComponent($c); $b->setComponent($a); $b->operation();
看完之後,我凌亂了