/**
*
*/
package com.sean.composite;
/**
* @author Sean_Zhang
*
*/
public interface Graphic {
public void print();
}
/**
*
*/
package com.sean.composite;
/**
* @author Sean_Zhang
*
*/
public class Ellipse implements Graphic {
/* (non-Javadoc)
* @see com.sean.composite.Graphic#print()
*/
public void print() {
System.out.println("ellipse");
}
}
/**
*
*/
package com.sean.composite;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sean_Zhang
*
*/
public class CompositeGraphic implements Graphic {
private List<Graphic> childGraphics = new ArrayList<Graphic>();
/* (non-Javadoc)
* @see com.sean.composite.Graphic#print()
*/
public void print() {
for(Graphic graphic : childGraphics) {
graphic.print();
}
}
public void add(Graphic graphic) {
childGraphics.add(graphic);
}
public void remove(Graphic graphic) {
childGraphics.remove(graphic);
}
}