docs/DesignPatterns

view code/composite-composite.java @ 37:debbd3bf76ce

Added tag Ausarbeitung final for changeset f03413250b39d73ca44b22ea1e4022fd3c9e825d
author meillo@marmaro.de
date Sat, 11 Aug 2007 22:43:34 +0200
parents 20c0116dcb97
children
line source
1 class Composite implements IComponent {
2 private String id;
3 private List<IComponent> list = new ArrayList<IComponent> ();
5 public Composite(String id) {
6 this.id = id;
7 }
9 public String toString() {
10 StringBuilder buf = new StringBuilder();
11 buf.append(String.format("(%s:", id));
13 for (IComponent child : list) {
14 buf.append(" " + child.toString());
15 }
16 buf.append(")");
18 return buf.toString();
19 }
21 //public List<IComponent> getChildren()
23 public Collection getChildren(){
24 return list;
25 }
27 public boolean addComponent(IComponent c){
28 return list.add(c);
29 }
31 public boolean removeComponent(IComponent c){
32 return list.remove(c);
33 }
34 }