Gof Composite

Composite in modern Java: treating a leaf and a tree of leaves through one interface, and the hazards that come with a recursive structure. Covers the transparent-versus-safe trade-off and when a sealed interface with exhaustive pattern matching changes that trade-off, unbounded depth and StackOverflowError, cycles introduced by parent pointers and the infinite recursion they cause in equals, hashCode and toString, mutation during traversal, and why a tree whose children live in other services is not this pattern. Use when a part-whole hierarchy is being modelled, when a leaf class is forced to implement add() and throw, when a recursive walk overflows the stack on production data, when nested structures arrive from untrusted input, or when someone proposes Composite for a flat group of items. Does not cover adding operations over a tree (gof-visitor), traversal protocols (gof-iterator), adding behaviour to one object (gof-decorator), or aggregate boundaries in a domain model (domain-logic-organization).

robsonkades Updated

File contents

robsonkades/agent-skills/tree/main/skills/gof-composite commit dd7e5cc052

Frequently asked questions

npx skillmds@latest add robsonkades/gof-composite