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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access