FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaCodeAcc/src/designpattern/composite/CompositeClient.java at master · kylez7/JavaCodeAcc · GitHub
kylez7
/
JavaCodeAcc
Public
forked from
echoTheLiar/JavaCodeAcc
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaCodeAcc
/
src
/
designpattern
/
composite
/
CompositeClient.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (27 loc) · 923 Bytes
Breadcrumbs
JavaCodeAcc
/
src
/
designpattern
/
composite
/
CompositeClient.java
Copy path
File metadata and controls
32 lines (27 loc) · 923 Bytes
Raw
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
package
designpattern
.
composite
;
/**
* 客户端。通过Component接口操作组合部件的对象
*
* @author liu yuning
*
*/
public
class
CompositeClient
{
public
static
void
main
(
String
[]
args
) {
// 生成树根,根上长出两叶Leaf A和Leaf B
Composite
root
=
new
Composite
(
"root"
);
root
.
add
(
new
Leaf
(
"Leaf A"
));
root
.
add
(
new
Leaf
(
"Leaf B"
));
// 根上长出分支Composite X,分支上也有两叶Leaf X-A和Leaf X-B
Composite
compositeX
=
new
Composite
(
"Composite X"
);
compositeX
.
add
(
new
Leaf
(
"Leaf X-A"
));
compositeX
.
add
(
new
Leaf
(
"Leaf X-B"
));
root
.
add
(
compositeX
);
// 在Composite X上再长出分支Composite X-Y,分支上也有两叶Leaf X-Y-A和Leaf X-Y-B
Composite
compositeXY
=
new
Composite
(
"Composite X-Y"
);
compositeXY
.
add
(
new
Leaf
(
"Leaf X-Y-A"
));
compositeXY
.
add
(
new
Leaf
(
"Leaf X-Y-B"
));
compositeX
.
add
(
compositeXY
);
// 显示大树的样子
root
.
display
(
1
);
}
}
Back
|
FazBrowse Home
|
New Git URL