views:

132

answers:

5

In .NET architecture,there are lot of design patterns.I want to know about what is meant with observer pattern and how it is implemented

+1  A: 

A good example of observer pattern is shown on MSDN.

You can find it here :

http://msdn.microsoft.com/en-us/library/ms998543.aspx

Thomas Jaskula
+1  A: 

Check out DOFactory.

They have :

  • UML diagrams Advantages Disadvantages
  • Summary of main items involved C#
  • implementation C# implementation for
  • sample problem.
Ian
A: 

Have a look at this tutorial.

LnDCobra
+2  A: 

Wikipedia summarises it best:

The observer pattern (a subset of the publish/subscribe pattern) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.

An Observer (sometimes known as publish-subscribe pattern) is best used on GUI interfaces to update states of change on GUI objects such as all other objects can update itself (e.g. resizing a window, then all gui objects such as buttons can re-align itself based on window's size). This is usually done by introducing EventListeners (which is an Observer pattern).

For implementation, you can view the tutorial from either:

Hope this helps.

The Elite Gentleman
+4  A: 

The Observer pattern is pretty much reified in C# as events.

kyoryu
This is the only correct answer. The Observer is implemented by C# language.
Vasiliy Borovyak
@Vasiliy....He asked what is Observer pattern. Telling the OP that events in C# are observer patterns doesn't explain what Observers are.
The Elite Gentleman
The OP should get a book. Kyoryu rescued the question.
Hans Passant