7.2. UML

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

Figure 7-1. Figure 7-1

Looking at this figure, you'll note that:

  • The base class MyObject is aware that it will be using objects based on the Delegate Design Pattern. It contains a private string delegateType and a private instance of MyDelegateObject, called internalDelegate.

  • The setDelegateType() method receives a parameter named type. This is stored in the delegateType string.

  • The createDelegateObject() method will create an instance of a delegate object named after the delegateType variable. It then stores the instance internally by assigning it to internalDelegate.

  • The runDelegateAction() method is responsible for running the action() method of the internalDelegate object.

  • MyDelegateObject contains the logic responsible for this particular action. The action() method is run by MyObject to accomplish the feature.

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.