// Mobile Package Fee interface Abstract class iphonepackpagefee{ protectedabstractfunction spendfee (); Public $Fee ;}
// basic consumption Monthfee extends iphonepackpagefee{ public function __construct ( $fee ) { $this ->fee= $fee public function Spendfee () { echo ("Base package Fee:". ->fee); echo ("
Decorative base class:
// Decoration class class extends iphonepackpagefee{ private $exFee; function $exfee ) { $this->exfee=$exfee; } Public function Spendfee () { $this->exfee->spendfee (); }}
classMobileflowextendsdecoratorservice{function__construct (Decoratorservice$exService,$fee) {Parent:: __construct ($exService); $this->fee=$fee; } Public functionSpendfee () {$this-Spendflow (); Parent::Spendfee (); } Private functionSpendflow () {Echo("Traffic charges:".)$this-Fee); Echo("<br/>"); }}
Call:
Echo ("PHP decoration mode:"); Echo ("); $monthfee=new monthfee (+); $decorator=new decoratorservice ($monthfee); $flow=new mobileflow ($decorator,N); $flow->spendfee ();
PHP design mode--decoration mode