Download - Composite Design Pattern
![Page 1: Composite Design Pattern](https://reader036.vdocument.in/reader036/viewer/2022082810/55849248d8b42a05388b484d/html5/thumbnails/1.jpg)
Composite Design Pattern
by:Dela Cruz, Evangelista,
Felisco, Jumawan
REFERENCE: http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-designpatterns.html http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-designpatterns.html
![Page 2: Composite Design Pattern](https://reader036.vdocument.in/reader036/viewer/2022082810/55849248d8b42a05388b484d/html5/thumbnails/2.jpg)
Composite Objects
Objects that contain other objects It compose objects into tree
structures to represent part-whole hierarchies.
Example: A drawing may be composed of
graphic primitives, such as lines, circles, rectangles, text, and so on.
![Page 3: Composite Design Pattern](https://reader036.vdocument.in/reader036/viewer/2022082810/55849248d8b42a05388b484d/html5/thumbnails/3.jpg)
Problems Resolved
It lets clients treat individual objects and compositions of objects uniformly.
We often must manipulate composites exactly the same way we manipulate primitive objects.
![Page 4: Composite Design Pattern](https://reader036.vdocument.in/reader036/viewer/2022082810/55849248d8b42a05388b484d/html5/thumbnails/4.jpg)
Sample Code(Composite method)
public void draw() { // Iterate over the components for(int i=0; i < getComponentCount(); ++i) { // Obtain a reference to the component and invoke its draw method Component component = getComponent(i); component.draw(); } }