Lecture overview -- Keyboard shortcut: 'u'  Previous page: Motivation - Example -- Keyboard shortcut: 'p'  Next page: An Observer Example -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 17 : 20
Object-oriented Programming in C#
Operators, Delegates, and Events
The observer design pattern

The subject (weather service object) to the left and its three observers (weather watcher objects) to the right. The Weather Service Object get its information various sensors.

The Observer is often used to ensure a loose coupling between an application and its user interface

In general, Observer can be used whenever a set of observer objects need to be informed about state changes in a subject object

The loose couple is ensured by observers that subscribe to events from the subjects. Upon interesting and relevant events in the subject, the subject broadcasts to its observers. The observers may then ask the subject to supply additional information.

The main resposibility is shifted from the subject to the observers.


/user/normark/oop-csharp-1/sources/c-sharp/patterns/observer/template/subject-only.csTemplate of the Subject class. This program is explained

The subject class corresponds to the Weather Service.

/user/normark/oop-csharp-1/sources/c-sharp/patterns/observer/template/observer-only.csA templates of the Observer class. This program is explained

The observer class corresponds to a Weather Watcher.

/user/normark/oop-csharp-1/sources/c-sharp/patterns/observer/template/client.csApplication of the Subject and Observer classes. This program is explained

A client class that sets up the subject and the observers, handles subscriptions, and notifies the subject.