composite1.java.svn-base

来自「这个是我做j2ee培训时候自己整理和编写的设计模式的学习例子」· SVN-BASE 代码 · 共 37 行

SVN-BASE
37
字号
package org.hyq.composite;

import java.util.*;

public class Composite1 extends Composite {

	private List<Composite> childrenList;

	public Composite1(String name) {
		super(name);
		childrenList = new ArrayList<Composite>();
	}

	public boolean addCIF(Composite cif) {// 添加一个子类
		return childrenList.add(cif);
	}

	public boolean removeCIF(Composite cif) {// 删除一个子类
		return childrenList.remove(cif);
	}

	public Iterator<Composite> getChildren() {// 返回子类的迭代器
		return childrenList.iterator();
	}

	@Override
	public void Work(String str) {
		System.out.println(str + "/" + getName());
		Iterator<Composite> iter = getChildren();
		while (iter.hasNext()) {
			((Composite) (iter.next())).Work(str + "/" + getName());
		}

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?