Observer Pattern Examples - Weather data - Illustrate the "bad choice" - Newspaper publish/subscribe idea - How to represent this in code? Design Principle: Stive for loosely coupled designs between objects that interact. - That is, the objects are somewhat independent, but communicate now and then. Loose coupling allows what those objects do precisely to change more easily. First solution to weather station stuff: - What about the way in which we're passing the data as arguments to the update method? - Subject pointer in observer: if update() passes the data, why do we need this? ANS: to unregister later. - How could we make WeatherStation and WeatherData observers? Push/pull of state - Pull: have separate getter methods. If we add new state, old code unchanged. java.util.Observable - Show Javadoc - Draw picture - setChanged vs. not having it - how would you use it? They wave their hands for the weather station, so how would you actually do it? - How could we change Observable and Observer to use generics? Why do you think that the Java library writers didn't do this? - Swing example - Bullet points on p. 74