forked from echoTheLiar/JavaCodeAcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.java
More file actions
41 lines (30 loc) · 755 Bytes
/
Command.java
File metadata and controls
41 lines (30 loc) · 755 Bytes
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
package designpattern.command;
import java.util.List;
/**
* 用来声明执行操作的接口
*
* @author liu yuning
*
*/
public abstract class Command {
protected List<Reciever> recievers;
public Command(List<Reciever> recievers) {
this.recievers = recievers;
}
public void addRecievers(Reciever reciever) {
this.recievers.add(reciever);
}
public abstract void execute();
}
// 将一个接收者对象绑定于一个动作,调用接收者相应的操作,以实现execute
class ConcreteCommand extends Command {
public ConcreteCommand(List<Reciever> recievers) {
super(recievers);
}
@Override
public void execute() {
for (Reciever reciever : recievers) {
reciever.action();
}
}
}