ccplusplus.com
Learn C, C++ Concepts
Sunday, January 1, 2012
momento design pattern example c++
/******************************************************************* * File : momento-pattern.cpp * Author : Saurabh Gupta * Description : momento design pattern 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 & strString, const string strTempString) : m_strOldString(strString) { strString = strTempString; } void revert(string & strString) { strString = m_strOldString; } }; void ccplusplus(CMementoPattern & memento) { string strMessage; memento.revert(strMessage); cout << strMessage << endl; } int main() { string hw("c cplusplus"); CMementoPattern mem(hw, "Goodbye, Saurabh"); ccplusplus(mem); return 0; } /* * OUTPUT * [sgupta@rhel55x86 momemto]$ c++ momento-pattern.cpp -o momento-pattern [sgupta@rhel55x86 momemto]$ ./momento-pattern c cplusplus [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