CSC/ECE 517 Fall 2010/ch3 3f DF: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 47: | Line 47: | ||
== Dynamic Language Implementation == | == Dynamic Language Implementation == | ||
Ruby | |||
=== | === Implementation === | ||
<pre> | <pre> | ||
Singleton pattern source code | Singleton pattern source code | ||
</pre> | </pre> | ||
Usage | === Usage === | ||
<pre> | <pre> | ||
class MySingleton | class MySingleton |
Revision as of 05:56, 4 October 2010
The Singleton pattern in static and dynamic languages
Introduction
Text overview
UML Diagram
Static Language Implementation
C++
class MySingleton { public: static MySingleton* Instance() { if(s_pSingletonObject == NULL) s_pSingletonObject = new MySingleton; return s_pSingletonObject; } static void Destroy() { if(s_pSingletonObject != NULL) { delete s_pSingletonObject; s_pSingletonObject = NULL; } } //Begin interface functions //... //End interface functions private: //Direct access to the constructor/destructor is prohibited MySingleton() {} virtual ~MySingleton() {} static MySingleton* s_pSingletonObject; };
Dynamic Language Implementation
Ruby
Implementation
Singleton pattern source code
Usage
class MySingleton include Singleton //Begin interface methods //... //End interface methods end