Adorner mode, decorative mode
Adorner mode
Php//Adorner mode-complements the function of the class without changing the structure of the original class//Weapon base classAbstract classweapon{Abstract Public functiondescriptions (); Abstract Public functionCost ();}//Sword ClassclassGlaveextendsweapon{ Public functiondescriptions () {return' Glave '; } Public functionCost () {return"100"; }}//Dagger classclassKnifeextendsweapon{ Public functiondescriptions () {return __class__; } Public functionCost () {return"80"; }}//Axe classclassAxeextendsweapon{ Public functiondescriptions () {return __class__; } Public functionCost () {return"200"; }}//Attribute ClassclassPropertyextendsweapon{protected $_weapon=NULL; protected $_price= 0; protected $_descriptions= ''; Public function__construct (weapon$weapon){ $this->_weapon =$weapon; } Public functionCost () {return $this->_weapon->cost () +$this-_price; } Public functiondescriptions () {return $this->_weapon->descriptions ().$this-_descriptions; }}//Power PropertiesclassStrengthextendsproperty{protected $_price= 30; protected $_descriptions= ' + Strength ';}//Agile PropertiesclassAgilityextendsproperty{protected $_price= 50; protected $_descriptions= ' + Agility ';}//Intellectual PropertiesclassIntellectextendsproperty{protected $_price= 20; protected $_descriptions= ' + Intellect ';}$weapon=NewAgility (NewStrength (NewStrength (NewGlave () )));Echo $weapon-Cost ();Echo $weapon->descriptions ();
http://www.bkjia.com/PHPjc/983244.html www.bkjia.com true http://www.bkjia.com/PHPjc/983244.html techarticle decorator mode, decorative mode decorator mode? PHP//Decorator mode-the function of the class is supplemented//weapon-based class abstract class weapon{abst, without changing the structure of the original class .