ccplusplus.com
Learn C, C++ Concepts
Wednesday, January 11, 2012
chain of responsibility example c++
/*************************************************************************************** * File : chain-of-responsibility.cpp * Author : Saurabh Gupta * Description : chain of responsibility 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 <string> #include <iostream> 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]$ */
Note:
display-message.cpp that is used to explain the design pattern
See Also:
Design pattern Concept and Sample Codes
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment