added composite sample

This commit is contained in:
Ilkka Seppala
2014-08-13 21:14:03 +03:00
parent 6a3c206bce
commit 0c9136ac01
8 changed files with 184 additions and 0 deletions
@@ -0,0 +1,29 @@
package com.iluwatar;
import java.util.ArrayList;
import java.util.List;
public abstract class LetterComposite {
private List<LetterComposite> children = new ArrayList<LetterComposite>();
public void add(LetterComposite letter) {
children.add(letter);
}
public int count() {
return children.size();
}
protected abstract void printThisBefore();
protected abstract void printThisAfter();
public void print() {
printThisBefore();
for (LetterComposite letter: children) {
letter.print();
}
printThisAfter();
}
}