The Composite pattern is a structural GoF design pattern by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides that composes objects into tree structures to represent part-whole hierarchies. Individual objects and compositions share one interface, so clients treat them uniformly and can ignore the difference between a single object and a group, as when files and folders in a file system are handled the same way.

GoF-Composite Pattern

Details
Full Name

GoF Composite Pattern (Structural)

Intent:

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions uniformly.

When to Use:

  • When you want to represent part-whole hierarchies of objects

  • When you want clients to be able to ignore the difference between compositions of objects and individual objects

Prompt Example:

"Modelliere das Dateisystem nach dem GoF-Composite Pattern, sodass Dateien und Ordner einheitlich behandelt werden können."