
Hierarchical representation of an object structure
where each object works on the same interfcae -> uniformity
if (object instanceof (Composite)){
// do what a composite does
}
if (object instanceof (Leaft){
// do what a Leaf does
}
pros: consistent interface
cons: possibile illegal method call at runtime
pros: no illegal method call at runtime
cons: inconsistent interface
->type checking and type conversion may be required
A client may want to access each Component
Composite's data structure vaires for composing component objects such as tree, graph or even hashmap
How to let a client access each Component, while hidding the internal implementation of data structure?
-> Iterator
Both involve recursive composition for an open-ended number of objects.
But Decorator adds responsibilities,

while Composite provides a uniform object representation

they often work in collaboration