Thursday, March 4, 2010

Singleton Exmple

Building off of my last post, I am going to post a singleton example that performs geographic functions.


1) Create your Singleton classHere there is a singleton class that will return the same instance of the object every time a specific class is called.
2) Create your class and have it inherit from Singleton


Now to use this, simply create a __main__ declaration, and create the object GeometryObject()


This gives you the output of:


Notice that GO and GO2 are the same exact object. This is what you want if you create a Singleton, only one instance of the object.

No comments: