Child management

While the composite pattern tries to equalize different kinds of objects in a data structure, there is still a significant difference between compound and leaf nodes, namely that compound nodes own other objects. To use this functionality in the code, compound nodes must implement child management operations. In other words, they must implement operations for adding, removing, and accessing child objects. It is, however, not clear in which place the class hierarchy we should implement these methods.

We can approach this in two different ways. One possibility is to define these operations in the interface class (TBaseClass in our example). This is called design for uniformity and enables the clients to treat leaf and composite ...

Get Mastering Delphi Programming: A Complete Reference Guide 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.