Skip to content

Commit 277b9b7

Browse files
authored
访问者模式
访问者模式
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy