Consequences of Cycles
Most operations on a composite, such as counting its number of leaf nodes, make sense even if the composite is not a tree. Usually, the only difference that nontree composites introduce is that you have to be careful to not operate on a given node twice. However, some operations become meaningless if the composite contains a cycle.
Operations that don't make sense if a composite contains cycles include any behavior that depends on the length of a path in the composite. For example, the height of a tree is the length of the longest path from the root to a leaf. This concept does not apply when cycles appear in a composite, as there is no limit to the length of some paths. In the fireworks process example, there is no “height” ...
Get Design Patterns Java™ Workbook 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.