Iterator
Definition-Provide a way to access the elements of an aggregate object equentially without exposing its underlying representation.
Composite Pattern
Definition-Compose objects into tree structures to represent part-whole hierarchies.Composite lets clients treat individual objects and compositions of objects uniformly. This is called recursive composition.
//UML Picture
Use the Composite pattern when
- You want to represent part-whole hierarchies of objects
- You want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly.
Benefits
-It makes it easy to add new kinds of components
-It makes clients simpler, since they do not have to know if they are dealing with a leaf or a composite component
Liabilities
It makes it harder to restrict the type of components of a composite
//Example
//code
//Graphic.java























































































//Main.java





























//results
//if u have anything interesting, pls contact with me.QQ:95491590