ccplusplus.com
Learn C, C++ Concepts
Wednesday, December 21, 2011
chain of responsibility design pattern example
/*************************************************************************************** * File : chain-of-responsibility.cpp * Author : Saurabh Gupta * Description : Chain of responsibility design pattern example c++ * : Performs staged processing using a series of different objects. * Date : AM 09:13 11 January 2012 * Source : http://www.ccplusplus.com/2011/07/design-pattern-guide-with-example-and.html * Note : ***************************************************************************************/ #include
#include
class COutput { public: void m_output(const std::string & str) { std::cout << str << std::endl; } }; class CMessage { private: COutput & out; public: CMessage(COutput & out) : out(out) { } void m_output(const std::string & str) { out.m_output(str + "ccplusplus.com"); } }; class CDisplay { private: CMessage & msg; public: CDisplay(CMessage & msg) : msg(msg) { } void m_output() { msg.m_output("www."); } }; void display_message(CDisplay & disp) { disp.m_output(); } int main() { COutput m_output; CMessage msg(m_output); CDisplay disp(msg); display_message(disp); return 0; } /* * OUTPUT * [sgupta@rhel6x64 chain-of-responsibility]$ c++ chain-of-responsibility.cpp -o chain-of-responsibility [sgupta@rhel6x64 chain-of-responsibility]$ ./chain-of-responsibility www.ccplusplus.com [sgupta@rhel6x64 chain-of-responsibility]$ */
See Also:
Design Pattern Concepts and Example C++ Codes
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment