-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDS17_Mediator.java
More file actions
64 lines (46 loc) · 1.16 KB
/
DS17_Mediator.java
File metadata and controls
64 lines (46 loc) · 1.16 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//Mediator
abstract class Mediator {
public abstract void notice(String content);
}
//ConcreteMediator
class ConcreteMediator extends Mediator {
private ColleagueA ca;
private ColleagueB cb;
public ConcreteMediator() {
ca = new ColleagueA();
cb = new ColleagueB();
}
public void notice(String content) {
if (content.equals("boss")) {
//老板来了, 通知员工A
ca.action();
}
if (content.equals("client")) {
//客户来了,通知前台B
cb.action();
}
}
}
abstract class Colleague{
public abstract void action();
}
//Colleagueclass
class ColleagueA extends Colleague {
public void action(){
System.out.println("普通员工努力工作");
}
}
class ColleagueB extends Colleague {
public void action() {
System.out.println("前台注意了!");
}
}
public class DS17_Mediator {
public static void main(String[] args) {
Mediator med = new ConcreteMediator();
//老板来了
med.notice("boss");
//客户来了
med.notice("client");
}
}