Composite
Example - Simple Composite
class TreeNode {
private String name;
private List<TreeNode> children = new ArrayList<>();
public TreeNode(String name) {
this.name = name;
}
public void addChild(TreeNode child) {
children.add(child);
}
public boolean isLeaf() {
return children.size() == 0;
}
}Example - Composite with an interface
Complex example with simple algorithm
Last updated