For the desired effect to occur, a single instance of PortRegistry must
be shared: this is the role of the Singleton pattern.
To prevent the creation of more than one instance, all constructors are private, and the class is final, so it may not be subclassed. The class method (i.e. static method in Java) getDefaultRegistry() returns a reference to the private class member reg of type PortRegistry--instantiating reg the first time it is invoked. |