Observer Design Pattern
page 1 of 5
Published: 22 Jun 2006
Unedited - Community Contributed
In this article, Vishal demonstrates the Observer Design pattern with the help of non-software and .NET Framework examples.
by Vishal Patil
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22854/ 57


Good object-oriented design emphasizes both encapsulation and loose coupling.  The Observer Pattern is a mechanism for drastically reducing coupling between interacting classes.  The observer pattern should be used whenever one or more objects (observers) must track changes in the subject.  In most applications, classes do not work in isolation; they interact with many other classes.  A common scenario of class interaction occurs when one class (the Observer) needs to be notified when something changes in another (the Subject).

In this pattern, an observer registers with a subject and subsequently receives notifications and is usually encountered both in everyday life and in the software Development applications.

Its intent is to define a one-to-many dependency between objects so that when one object changes state all its dependents are notified and updated automatically

This pattern allows us to plug objects into a framework at runtime, which allows for highly flexible, extensible, and reusable software.

This pattern is also called the Publish-Subscribe pattern.

Observer pattern can be applied in any of the following situations.

1.      It can be applied when the abstraction has two aspects with one dependent on the other. Encapsulating these aspects in separate objects will increase the chance to reuse them independently.

2.      Use it when the subject object does not know exactly how many observer objects it has.

3.      Or use it when the subject object should be able to notify its observer objects without knowing who these objects are.

The following Non-software and .NET Framework examples demonstrate this pattern.

View Entire Article

User Comments

Title: Easy to understand   
Name: Vijay
Date: 2007-06-01 9:16:14 AM

I have browsed for many articles in the net and your articles on design patterns are really simple and easy to understand. Your work on this is really appreciated.

Title: Good article   
Name: Vikram
Date: 2006-06-29 4:46:34 AM
Nice article.. Vishal. written in very simple language and the use of non software examples make it very easy to grasp the fundamentals behind the pattern.great goin.. more articles on design patterns would be higly appreciated.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-25 12:23:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search