forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
38 lines (30 loc) · 966 Bytes
/
App.java
File metadata and controls
38 lines (30 loc) · 966 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
package com.iluwatar;
import com.iluwatar.generic.GHobbits;
import com.iluwatar.generic.GOrcs;
import com.iluwatar.generic.GWeather;
/**
*
* Observer pattern defines one-to-many relationship between objects. The target
* object sends change notifications to its registered observers.
*
*/
public class App {
public static void main(String[] args) {
Weather weather = new Weather();
weather.addObserver(new Orcs());
weather.addObserver(new Hobbits());
weather.timePasses();
weather.timePasses();
weather.timePasses();
weather.timePasses();
// Generic observer inspired by Java Generics and Collection by Naftalin & Wadler
System.out.println("\n--Running generic version--");
GWeather gWeather = new GWeather();
gWeather.addObserver(new GOrcs());
gWeather.addObserver(new GHobbits());
gWeather.timePasses();
gWeather.timePasses();
gWeather.timePasses();
gWeather.timePasses();
}
}