1.4.1. Composite Intent

From the book:

Intent: “Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.” (GoF 1994, p. 163)


Part-Whole Hierarchy?

Non-native English speakers often struggle with the term “part-whole hierarchy”. The Dictionary.com definition of part is “a piece or portion of a whole'" and of whole is "`the whole assemblage of parts or elements belonging to a thing”.

An object is either a part of a whole or it is the whole made up of parts. For example, a file is part of a directory, and a directory contains files and potentially other directories. One of the constraints of part-whole is that the object graph must by its definition be non-circular. This is not a bad constraint. Traversals over circular data structures may cause infinite loops or terminate with a StackOverflowError.

Complete and Continue  
Discussion

0 comments