Design pattern--Responsibility Chain mode (c + + implementation)

Source: Internet
Author: User

 

1#include <iostream>2#include <string>3 4 using namespacestd;5 6 7 classHandler8 {9  Public:TenHandler (handler*Psthandler): M_psthandler (Psthandler) One         { A  -         } -  the         Virtual voidHandleRequest (intRequest) =0; -  - protected: -handler*M_psthandler; + }; -  + classConcreteHandler1: PublicHandler A { at  Public: -ConcreteHandler1 (handler*Psthandler): Handler (Psthandler) -         { -  -         } -  in         Virtual voidHandleRequest (intrequest) -         { to                 if(Request <7) +                 { -cout<<"Group Leader: Granting"<< request<<"days"<<Endl; the                 } *                 Else $                 {Panax NotoginsengM_psthandler->HandleRequest (request); -                 } the         } + }; A  the classConcreteHandler2: PublicHandler + { -  Public: $ConcreteHandler2 (handler*Psthandler): Handler (Psthandler) $         { -  -         } the  -         Virtual voidHandleRequest (intrequest)Wuyi         { the                 if(Request < the) -                 { Wucout<<"Director: Granting"<< request<<"days"<<Endl; -                 } About                 Else $                 { -M_psthandler->HandleRequest (request); -                 } -         } A }; +  the classConcreteHandler3: PublicHandler - { $  Public: theConcreteHandler3 (handler*Psthandler): Handler (Psthandler) the         { the  the         } -  in         Virtual voidHandleRequest (intrequest) the         { the                 if(Request < -) About                 { thecout<<"Manager: Granting"<< request<<"days"<<Endl; the                 } the                 Else +                 { -cout<<"Manager:"<< request<<"days, the time was too long to exceed the company's rules"<<Endl; the                 }Bayi         } the }; the  - intMainintargcChar*argv[]) - { thehandler* Jingli =NewConcreteHandler3 (NULL); thehandler* Zongjian =NewConcreteHandler2 (Jingli); thehandler* Zuzhang =NewConcreteHandler1 (Zongjian); the  -Zuzhang->handlerequest ( A); theZuzhang->handlerequest ( the); theZuzhang->handlerequest (5); theZuzhang->handlerequest ( to);94  the         DeleteJingli; the         DeleteZongjian; the         DeleteZuzhang;98  About         return 0; - }101 //////////////////////////////////102[Email protected] ~/learn_code/design_pattern/20_chain]$.chain103 Director: Granting 12 days104 Manager: Granting 15 days the Group Leader: granting 5 days106Manager: 31 days, the time is too long, over the company rules

Design pattern--Responsibility Chain mode (c + + implementation)

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.