Responsibility chain Mode-design mode-PHP version

Source: Internet
Author: User

1<?PHP2 /*3 * Responsibility Chain mode4  * 5 * Reference: http://blog.csdn.net/jhq0113/article/details/464544196  * 7  */8 //Apply for Model9 classRequest {Ten     //Quantity One      Public $num; A     //Application Type -      Public $requestType; -     //Request Content the      Public $requestContent; - } - //Abstract Manager - Abstract classManager { +     protected $name; -     //Senior Manager +     protected $manager; A      Public function__construct ($_name) { at         $this->name =$_name; -     } -     //set up Manager Supervisor -      Public functionSetHeader (Manager$_mana) { -         $this->manager =$_mana; -     } in     //Request for Application -     Abstract  Public functionApply (Request$_req); to } + //Manager - classCommonmanagerextendsManager { the      Public function__construct ($_name) { *Parent::__construct ($_name); $     }Panax Notoginseng      Public functionApply (Request$_req) { -         if($_req->requesttype = = "Leave" &&$_req->num <= 2) { the             Echo"{$this->name}:{$_req->requestcontent} number {$_req->num} is approved. <br/> "; +}Else { A             if(isset($this-manager)) { the                 $this->manager->apply ($_req); +             } -         } $     } $ } - //Director - classMajordomoextendsManager { the      Public function__construct ($_name) { -Parent::__construct ($_name);Wuyi     } the      Public functionApply (Request$_req) { -         if($_req->requesttype = = "Leave" &&$_req->num <= 5) { Wu             Echo"{$this->name}:{$_req->requestcontent} number {$_req->num} is approved. <br/> "; -}Else { About             if(isset($this-manager)) { $                 $this->manager->apply ($_req); -             } -         } -     } A } + //General Manager the classGeneralmanagerextendsManager { -      Public function__construct ($_name) { $Parent::__construct ($_name); the     } the      Public functionApply (Request$_req) { the         if($_req->requesttype = = "Leave") { the             Echo"{$this->name}:{$_req->requestcontent} number {$_req->num} is approved. <br/> "; -}Else if($_req->requesttype = = "Pay rise" &&$_req->num <= 500) { in             Echo"{$this->name}:{$_req->requestcontent} number {$_req->num} is approved. <br/> "; the}Else if($_req->requesttype = = "Pay rise" &&$_req->num > 500) { the             Echo"{$this->name}:{$_req->requestcontent} number {$_req->num} say it again. <br/> "; About         } the     } the } the //--------------------Client---------------------- + $jingli=NewCommonmanager ("manager Li")); - $zongjian=NewMajordomo ("director Guo")); the $zongjingli=NewGeneralmanager ("Sun Total"));Bayi //Set Direct ancestor the $jingli->setheader ($zongjian); the $zongjian->setheader ($zongjingli); - //Application - $req 1=NewRequest (); the $req 1->requesttype = "Leave"; the $req 1->requestcontent = "Vegetable leave!" "; the $req 1->num = 1; the $jingli->apply ($req 1); - $req 2=NewRequest (); the $req 2->requesttype = "Leave"; the $req 2->requestcontent = "Vegetable leave!" "; the $req 2->num = 4;94 $jingli->apply ($req 2); the $req 3=NewRequest (); the $req 3->requesttype = "Raise"; the $req 3->requestcontent = "side dishes ask for a raise!" ";98 $req 3->num = 500; About $jingli->apply ($req 3); - $req 4=NewRequest ();101 $req 4->requesttype = "Raise";102 $req 4->requestcontent = "side dishes ask for a raise!" ";103 $req 4->num = 1000;104 $jingli->apply ($req 4);

Responsibility chain Mode-design mode-PHP version

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.