|
6 | 6 |
|
7 | 7 | /** |
8 | 8 | * |
9 | | - * The Observer pattern is a software design pattern in which an object, called |
10 | | - * the subject, maintains a list of its dependents, called observers, and notifies |
11 | | - * them automatically of any state changes, usually by calling one of their methods. |
12 | | - * It is mainly used to implement distributed event handling systems. The Observer |
13 | | - * pattern is also a key part in the familiar model–view–controller (MVC) architectural |
14 | | - * pattern. The Observer pattern is implemented in numerous programming libraries and |
15 | | - * systems, including almost all GUI toolkits. |
| 9 | + * The Observer pattern is a software design pattern in which an object, called the subject, |
| 10 | + * maintains a list of its dependents, called observers, and notifies them automatically of any |
| 11 | + * state changes, usually by calling one of their methods. It is mainly used to implement |
| 12 | + * distributed event handling systems. The Observer pattern is also a key part in the familiar |
| 13 | + * model–view–controller (MVC) architectural pattern. The Observer pattern is implemented in |
| 14 | + * numerous programming libraries and systems, including almost all GUI toolkits. |
16 | 15 | * <p> |
17 | | - * In this example {@link Weather} has a state that can be observed. The {@link Orcs} |
18 | | - * and {@link Hobbits} register as observers and receive notifications when the |
19 | | - * {@link Weather} changes. |
| 16 | + * In this example {@link Weather} has a state that can be observed. The {@link Orcs} and |
| 17 | + * {@link Hobbits} register as observers and receive notifications when the {@link Weather} changes. |
20 | 18 | * |
21 | 19 | */ |
22 | 20 | public class App { |
23 | 21 |
|
24 | | - /** |
25 | | - * Program entry point |
26 | | - * @param args command line args |
27 | | - */ |
28 | | - public static void main(String[] args) { |
| 22 | + /** |
| 23 | + * Program entry point |
| 24 | + * |
| 25 | + * @param args command line args |
| 26 | + */ |
| 27 | + public static void main(String[] args) { |
29 | 28 |
|
30 | | - Weather weather = new Weather(); |
31 | | - weather.addObserver(new Orcs()); |
32 | | - weather.addObserver(new Hobbits()); |
| 29 | + Weather weather = new Weather(); |
| 30 | + weather.addObserver(new Orcs()); |
| 31 | + weather.addObserver(new Hobbits()); |
33 | 32 |
|
34 | | - weather.timePasses(); |
35 | | - weather.timePasses(); |
36 | | - weather.timePasses(); |
37 | | - weather.timePasses(); |
| 33 | + weather.timePasses(); |
| 34 | + weather.timePasses(); |
| 35 | + weather.timePasses(); |
| 36 | + weather.timePasses(); |
38 | 37 |
|
39 | | - // Generic observer inspired by Java Generics and Collection by Naftalin & Wadler |
40 | | - System.out.println("\n--Running generic version--"); |
41 | | - GWeather gWeather = new GWeather(); |
42 | | - gWeather.addObserver(new GOrcs()); |
43 | | - gWeather.addObserver(new GHobbits()); |
| 38 | + // Generic observer inspired by Java Generics and Collection by Naftalin & Wadler |
| 39 | + System.out.println("\n--Running generic version--"); |
| 40 | + GWeather gWeather = new GWeather(); |
| 41 | + gWeather.addObserver(new GOrcs()); |
| 42 | + gWeather.addObserver(new GHobbits()); |
44 | 43 |
|
45 | | - gWeather.timePasses(); |
46 | | - gWeather.timePasses(); |
47 | | - gWeather.timePasses(); |
48 | | - gWeather.timePasses(); |
49 | | - } |
| 44 | + gWeather.timePasses(); |
| 45 | + gWeather.timePasses(); |
| 46 | + gWeather.timePasses(); |
| 47 | + gWeather.timePasses(); |
| 48 | + } |
50 | 49 | } |
0 commit comments