The Singleton ensures a maximum of one instance is created by the JVM (not surprisingly, that’s why it’s called a singleton). To ensure you have control over the instantiation, make the constructor private. This poses a problem: it’s impossible to create an instance, so an accessor method is provided by a static method (getInstance()). That method creates the single instance, if it doesn't already exist, and returns the reference of the singleton to the caller of the method. The reference to the singleton is also stored as a static private attribute of the singleton class for future calls.
Silahkan Download Singleton Pattern
0 Comments:
Posting Komentar