mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 20:58:35 +00:00
30 lines
572 B
Java
30 lines
572 B
Java
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();
|
|
}
|
|
}
|