Printer Sharing:

In this example, the singleton pattern is used. The Printer (Singleton) class's constructor is private, so the class can not be instantiated. Using the private getInstance method, a Printer object is created. The MSWord (Client) and AcrobatReader (Client) objects are accessed the Printer object by calling the getInstance method. Then, these objects (MSWord, AcrobatReader) call the print method of the Printer object.


The generated java code of the printer sharing case study is below.

Singleton.pdf