ccplusplus.com
Learn C, C++ Concepts
Sunday, January 1, 2012
momento pattern example c++
/******************************************************************* * File : momento-pattern.cpp * Author : Saurabh Gupta * Description : momento pattern example c++ * memento stores a previous state or value so * that it can be restored at a later time. * Date : PM 10:53 01 January 2012 * Source : http://www.ccplusplus.com/2011/07/design-pattern-guide-with-example-and.html * Note : *******************************************************************/ #include <iostream> #include <string> using namespace std; class CMementoPattern { private: string m_strOldString; public: CMementoPattern(string & str, const string newString) : m_strOldString(str) { str = newString; } void undo(string & str) { str = m_strOldString; } }; void helloworld(CMementoPattern & memento) { string message; memento.undo(message); cout << message << endl; } int main() { string hw("Hello world!"); CMementoPattern mem(hw, "Goodbye, cruel world!"); helloworld(mem); return 0; } /* * OUTPUT * [sgupta@rhel55x86 momemto]$ c++ momento-pattern.cpp -o momento-pattern [sgupta@rhel55x86 momemto]$ ./momento-pattern Hello world! [sgupta@rhel55x86 momemto]$ */
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