-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListernerCommand.java
86 lines (56 loc) · 1.37 KB
/
ListernerCommand.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Solutions;
interface ActionListenerCommand {
public void execute();
}
class ActionOpen implements ActionListenerCommand {
private Document doc;
public ActionOpen(Document doc) {
this.doc = doc;
}
@Override
public void execute() {
doc.open();
}
}
class ActionSave implements ActionListenerCommand {
private Document doc;
public ActionSave(Document doc) {
this.doc = doc;
}
@Override
public void execute() {
doc.save();
}
}
class Document {
public void open() {
System.out.println("Document Opened");
}
public void save() {
System.out.println("Document Saved");
}
}
class MenuOptions {
private ActionListenerCommand openCommand;
private ActionListenerCommand saveCommand;
public MenuOptions(ActionListenerCommand open, ActionListenerCommand save) {
this.openCommand = open;
this.saveCommand = save;
}
public void clickOpen() {
openCommand.execute();
}
public void clickSave() {
saveCommand.execute();
}
}
public class ListernerCommand {
public static void main(String[] args) {
Document doc = new Document();
ActionListenerCommand clickOpen = new ActionOpen(doc);
ActionListenerCommand clickSave = new ActionSave(doc);
MenuOptions menu = new MenuOptions(clickOpen, clickSave);
menu.clickOpen();
menu.clickSave();
}
}