Problem Statement
How does Composite help model catalogs, folders, or organizational charts?
Explanation
Composite treats individual objects and compositions uniformly. A leaf and a node share the same interface, so traversal and operations look the same.
This simplifies tree operations like total price, permissions, or counts. You avoid special-case code for leaves versus groups and add new node types without breaking callers.
Code Solution
SolutionRead Only
interface Node{ total(): number }
class Item implements Node { total(){ return price; } }
class Bundle implements Node { total(){ return sum(children.total()); } }