Posts

Showing posts from December, 2013

The Java Enum: A Singleton Pattern

Image
The singleton pattern restricts the instantiation of a class to one object. In Java, to enforce this, the best approach is to use an enum. This great idea comes straight from the book Effective Java by Joshua Bloch. If you don't have it in your library, get it. One of the best Java books to date. There are a few reasons why one would use an enum as a singleton in Java: