public class EventAgent { // private constructor ensures no other instances private EventAgent() { } // static member variable and method enables callers // to get to the one-and-only object instance private static final EventAgent SINGLE_INSTANCE = new EventAgent(); public static EventAgent getInstance() { return SINGLE_INSTANCE; } ... }
Example 3: The Singleton design pattern.