@@ -0,0 +1,1381 @@
+// --------------------- %E6%8A%BD%E8%B1%A1%E6%9E%84%E4%BB%B6%0A%0Apublic abstract class Component %7B%0A    public void doSomething() %7B%0A        System.out.println(%22Component doSomething...%22);%0A    %7D%0A%7D%0A%0A// --------------------- %E6%A0%91%E6%9E%9D%E6%9E%84%E4%BB%B6%0A%0Apublic class Composite extends Component %7B%0A    private ArrayList%3CComponent%3E list = new ArrayList%3CComponent%3E();%0A%0A    public void add(Component component) %7B%0A        list.add(component);%0A    %7D%0A%0A    public void remove(Component component) %7B%0A        list.remove(component);%0A    %7D%0A%0A    public ArrayList%3CComponent%3E getChildren() %7B%0A        return list;%0A    %7D%0A%7D%0A%0Apublic class Leaf extends Component %7B%0A    public void doSomething() %7B%0A        System.out.println(%22Leaf doSomething...%22);%0A    %7D%0A%7D%0A%0A// --------------------- %E6%A0%91%E5%8F%B6%E6%9E%84%E4%BB%B6%0Apublic class Leaf extends Component %7B%0A    public void doSomething() %7B%0A        System.out.println(%22Leaf doSomething...%22);%0A    %7D%0A%7D%0A%0A// --------------------- test code%0A%0Apublic static void main(String%5B%5D args) %7B%0A    Composite root = new Composite();%0A    Composite branch = new Composite();%0A    Leaf leaf = new Leaf();%0A%0A    root.add(branch);%0A    branch.add(leaf);%0A%0A    root.doSomething();%0A    display(root);%0A%7D%0A%0Apublic static void display(Composite root) %7B%0A    for (Component ele : root.getChildren()) %7B%0A        if (ele instanceof Leaf) %7B%0A            ele.doSomething();%0A        %7D%0A        else %7B%0A            ele.doSomething();%0A            display((Composite) ele);%0A        %7D%0A    %7D%0A%7D

add component pattern