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

Sign up
Appearance settings

Commit 277b9b7

Browse files
访问者模式
访问者模式
1 parent 14630e6 commit 277b9b7

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.java.design.visitor;
2+
3+
public class BodyA {
4+
5+
public void seeABody() {
6+
7+
System.out.println("I see A の Body ...");
8+
}
9+
10+
public void seeBBody(BodyB b) {
11+
b.seeBBody(this);
12+
}
13+
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.java.design.visitor;
2+
3+
public class BodyB {
4+
5+
public void seeABody(BodyA a) {
6+
a.seeABody();
7+
}
8+
9+
public void seeBBody(BodyA a) {
10+
System.out.println("Want to see B の Body ? hehe ...");
11+
a.seeABody();
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.java.design.visitor;
2+
3+
/**
4+
* 访问者模式 -----> 表示一个作用于其对象结构中的各元素的操作,它使你可以在不改变各元素类的前提下定义作用于这些元素的新操作
5+
*
6+
* @author Administrator
7+
*
8+
*/
9+
public class VisitorPattern {
10+
11+
public static void main(String[] args) {
12+
13+
BodyA bodyA = new BodyA();
14+
bodyA.seeABody();
15+
bodyA.seeBBody(new BodyB());
16+
}
17+
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /