-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCook.java
More file actions
43 lines (40 loc) · 1.11 KB
/
Cook.java
File metadata and controls
43 lines (40 loc) · 1.11 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
/*
* @author Douglas Wendel
*
* The cook class implements subject and generates an
* array list to store the information given through.
* this class also allows the registration, removal
* notification of the observers and allows to enter
* a sighting returning the name at the end.
*/
package observerdesignpattern;
import java.util.ArrayList;
public class Cook implements Subject {
String name = "";
ArrayList<Observer> observers;
public Cook(String name) {
this.name = name;
this.observers = new ArrayList<Observer>();
}
@Override
public void registerObserver(Observer observer) {
if(!observers.contains(observer))
observers.add(observer);
}
@Override
public void removeObserver(Observer observer) {
if(observers.contains(observer))
observers.remove(observer);
}
@Override
public void notifyObservers(String location, String description) {
for(Observer observer : observers)
observer.update(location,description);
}
public void enterSighting(String location, String description) {
notifyObservers(location,description);
}
public String getName() {
return this.name;
}
}