9.2. UML

This Unified Modified Language (UML) diagram details a class design using the Factory Design Pattern (see Figure 9-1).

Figure 9-1. Figure 9-1

Note the following about this figure:

  • Two base classes exist: MyObjectTypeA and MyObjectTypeB. Both have a public method called doSomething(), which executes the logic of that object in its own unique way. Their public interfaces and return types are identical.

  • The MyObjectFactory class exists to create an instance of either one of these base classes and return it to the code stream. MyObjectFactory has one public method, named createObject(). This accepts a parameter called type. This helps determine which of the two base classes should be created. The createObject() method then returns an instance of the requested type class.

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.