16.2. UML

This Unified Modified Language (UML) diagram details a class design using the Singleton Design Pattern (see Figure 16-1). The following list details this pattern:

  • MyObject is designed as a Singleton. The constructor named MyObject() is a protected method.

  • The public method getInstance() is responsible for checking the protected variable named instance. If instance contains an instance of MyObject, it would simply return that instance. However, if instance is NULL, getInstance() will execute the protected MyObject() to construct a new MyObject. Then, it will store that instance of MyObject in the instance variable. Finally, it will return that instance variable.

Figure 16-1. Figure 16-1

Get Professional PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.