2014-08-22 21:57:54 +03:00
|
|
|
package com.iluwatar;
|
|
|
|
|
2014-11-11 23:15:13 +00:00
|
|
|
import com.iluwatar.generic.GHobbits;
|
|
|
|
import com.iluwatar.generic.GOrcs;
|
|
|
|
import com.iluwatar.generic.GWeather;
|
|
|
|
|
2014-08-31 11:17:21 +03:00
|
|
|
/**
|
2014-10-08 13:42:12 +01:00
|
|
|
*
|
2014-10-07 16:23:37 +01:00
|
|
|
* Observer pattern defines one-to-many relationship between objects. The target
|
|
|
|
* object sends change notifications to its registered observers.
|
2014-10-08 13:42:12 +01:00
|
|
|
*
|
2014-08-31 11:17:21 +03:00
|
|
|
*/
|
2014-10-07 16:23:37 +01:00
|
|
|
public class App {
|
|
|
|
|
2014-10-08 13:42:12 +01:00
|
|
|
public static void main(String[] args) {
|
2014-10-07 16:23:37 +01:00
|
|
|
|
2014-10-08 13:42:12 +01:00
|
|
|
Weather weather = new Weather();
|
|
|
|
weather.addObserver(new Orcs());
|
|
|
|
weather.addObserver(new Hobbits());
|
2014-10-07 16:23:37 +01:00
|
|
|
|
2014-10-08 13:42:12 +01:00
|
|
|
weather.timePasses();
|
|
|
|
weather.timePasses();
|
|
|
|
weather.timePasses();
|
|
|
|
weather.timePasses();
|
2014-08-22 21:57:54 +03:00
|
|
|
|
2014-11-11 23:15:13 +00:00
|
|
|
// Generic observer inspired by Java Generics and Collection by Naftalin & Wadler
|
2014-11-11 23:23:08 +00:00
|
|
|
System.out.println("\n--Running generic version--");
|
2014-11-11 23:15:13 +00:00
|
|
|
GWeather gWeather = new GWeather();
|
|
|
|
gWeather.addObserver(new GOrcs());
|
2014-11-11 23:23:08 +00:00
|
|
|
gWeather.addObserver(new GHobbits());
|
2014-11-11 23:15:13 +00:00
|
|
|
|
|
|
|
gWeather.timePasses();
|
|
|
|
gWeather.timePasses();
|
|
|
|
gWeather.timePasses();
|
|
|
|
gWeather.timePasses();
|
|
|
|
|
2014-10-08 13:42:12 +01:00
|
|
|
}
|
2014-08-22 21:57:54 +03:00
|
|
|
}
|