Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (32 loc) · 827 Bytes

File metadata and controls

42 lines (32 loc) · 827 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package designpattern.composite;
import java.util.ArrayList;
import java.util.List;
import util.StringUtil;
/**
* 定义有枝节点行为,用来存储子部件
*
* @author liu yuning
*
*/
public class Composite extends Component {
private List<Component> children = new ArrayList<Component>();
public Composite(String name) {
super(name);
}
@Override
public void add(Component component) {
children.add(component);
}
@Override
public void remove(Component component) {
children.remove(component);
}
@Override
public void display(int depth) {
// 显示其枝节点名称,并对其下级进行遍历
System.out.println(StringUtil.repeatableString("-", depth) + this.name);
for (Component component : children) {
component.display(depth + 2);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.