|
----------------------------------------------------------------
Head First Design Patterns
Chapter TWO - The Observer Pattern
----------------------------------------------------------------
"PUBLISHERS + SUBSCRIBERS = OBSERVER PATTERN"
Definition :-
The "Observer Pattern" defines a One-To-Many dependency between objects.
when one object changes state, all of its dependentsare notified and updated automatically.
ONE Subject to the MANY Observers !!!!
Subject can be anything which interests Observers.
Observers are objects who are interested in some Subject.
EXAMPLE : Newpaper Subscription where "Newspaper is Subject" and "Subscribers are Observers".
ONE Newspaper to MANY Subscribers.
DP1 : Strive for loosely coupled designs between objects that interact.
- Loosely coupled designs allow us to build flexible system that can handle changes becoz they minimize interdependency.
Note : Observer Pattern can be implemented using Events & Delegates in .Net, .Net 4.0 has now IObservable & IObserver interfaces to
facilitate the Observer Pattern.
This Example has implementations using Custom Interface & .Net in-house IObservable interface.
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Working in Software Development since 2007.
Work in .Net/VC++/COM.
work in Process Automation domain.