-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatalog.java
More file actions
51 lines (44 loc) · 1.3 KB
/
Copy pathCatalog.java
File metadata and controls
51 lines (44 loc) · 1.3 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
import java.util.ArrayList;
public class Catalog implements Subject {
private static Catalog instance = null;
private ArrayList<Course> courses;
private ArrayList<Observer> abonati;
private Catalog() {
courses = new ArrayList<Course>();
abonati = new ArrayList<Observer>();
}
public static Catalog getInstance() {
if (instance == null) {
instance = new Catalog();
}
return instance;
}
public void addCourse(Course course) {
courses.add(course);
}
public void removeCourse(Course course) {
courses.remove(course);
}
@Override
public void addObserver(Observer observer) {
abonati.add(observer);
}
@Override
public void removeObserver(Observer observer) {
abonati.remove(observer);
}
@Override
public void notifyObservers(Grade grade) {
for (Observer parinte : abonati) {
if (grade.getStudent().getMother() == parinte || grade.getStudent().getFather() == parinte) {
parinte.update(new Notification(grade));
}
}
}
@Override
public String toString() {
return "Catalog{" +
"courses=" + courses +
'}';
}
}