11.2. UML

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

Figure 11-1. Figure 11-1

For the figure, note that:

  • MyObject is the base object, which can be collected into countable collections. MyObject has a private string called name. This is used to represent the uniqueness of that particular object. The public method getName() provides the interface to determine what the name of the object is by retrieving it from the private name.

  • MyObjectCollection represents a class that manages collections of the object MyObject. The MyObjects array holds the collection of the objects. getMyObjects() provides the logic to create the collection and store the objects in the MyObject array.

  • The MyObjectCollectionIterator provides the interface to iterate over the objects stored in the MyObjectCollection. It has two public methods. hasNext() will let the caller know if there is another item left in the MyObjectCollection collection of MyObjects. The getNext() method will return the next MyObject from the array in MyObjectCollection.

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.