composite design pattern

Post on 20-Jun-2015

669 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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.

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.

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(); } }

top related