- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCook.java
More file actions
Latest commit
43 lines (40 loc) · 1.11 KB
/
Copy pathCook.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.
*/
packageobserverdesignpattern;
importjava.util.ArrayList;
publicclassCookimplementsSubject {
Stringname = "";
ArrayList<Observer> observers;
publicCook(Stringname) {
this.name = name;
this.observers = newArrayList<Observer>();
}
@Override
publicvoidregisterObserver(Observerobserver) {
if(!observers.contains(observer))
observers.add(observer);
}
@Override
publicvoidremoveObserver(Observerobserver) {
if(observers.contains(observer))
observers.remove(observer);
}
@Override
publicvoidnotifyObservers(Stringlocation, Stringdescription) {
for(Observerobserver : observers)
observer.update(location,description);
}
publicvoidenterSighting(Stringlocation, Stringdescription) {
notifyObservers(location,description);
}
publicStringgetName() {
returnthis.name;
}
}