Php design mode policy mode, php design mode. Php design mode policy mode, php design mode policy mode: encapsulate a group of specific behaviors and algorithms into classes to adapt to certain context environments. for example, assume that a php design mode is a policy mode, and a php design mode is
Rule mode:
Encapsulate a group of specific behaviors and algorithms into classes to adapt to certain context environments;
For example, in an e-commerce website system, for male and female users, they must jump to different product categories, and all advertising spaces should display different advertisements.
UserStrategy. php
FemaleUserStrategy. php
MaleUserStrategy. php
Index. php
class Page{ protected $strategy; function Index(){ $this->strategy->showAd(); echo '
'; $this->strategy->showCategory(); } function setStrategy(Baobab\UserStrategy $strategy){ $this->strategy = $strategy; }}$page = new Page();if (isset($_GET['female'])){ $strategy = new Baobab\FemaleUserStrategy();}else{ $strategy = new Baobab\MaleUserStrategy();}$page->setStrategy($strategy);$page->Index();
Ioc can be implemented using the policy mode, with dependency inversion and control inversion.
Strategy mode: php design mode. policy mode: encapsulates a group of specific behaviors and algorithms into a class to adapt to certain context environments. for example, if a set of policies is used...