Php design mode policy mode, php design mode _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.