🎨 Design Patterns (Gang of Four)
Beginner
What is the Composite design pattern?
Answer
The Composite pattern composes objects into tree structures to represent part-whole hierarchies, allowing clients to treat individual objects and compositions uniformly. Both leaf objects and container objects implement the same Component interface. For example, a file system has File (leaf) and Folder (composite) objects; calling getSize() on a Folder recursively sums the sizes of all its children. This pattern is ideal for UI widget hierarchies, organizational charts, and any domain where objects can be nested inside other objects of the same type.