ccplusplus.com
Learn C, C++ Concepts
Wednesday, January 4, 2012
prototype pattern example
/*************************************************************************************** * File : prototype-pattern.cpp * Author : Saurabh Gupta * Description : prototype design pattern example c++ * A Prototype is an object which is cloneable, i.e. you can create a * copy, even though you don't know what you are creating a copy of. * Date : AM 11:13 04 january 2012 * Source : http://www.ccplusplus.com/2011/07/design-pattern-guide-with-example-and.html * Note : ***************************************************************************************/ #include
#include
class CPrototypeOperation { public: virtual ~CPrototypeOperation() { } virtual std::auto_ptr
clone() const=0; virtual void m_Display()=0; }; class CDisplayMessage : public CPrototypeOperation { public: std::auto_ptr
clone() const { return std::auto_ptr
(new CDisplayMessage); } void m_Display() { std::cout << "www.ccplusplus.com" << std::endl; } }; void display_message(const CPrototypeOperation & something) { std::auto_ptr
clone = something.clone(); clone->m_Display(); } int main() { display_message(CDisplayMessage()); return 0; } /* * OUTPUT * [sgupta@rhel6x64 prototype]$ c++ prototype-pattern.cpp -o prototype-pattern [sgupta@rhel6x64 prototype]$ ./prototype-pattern www.ccplusplus.com [sgupta@rhel6x64 prototype]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment