How do you implement Observer Design Pattern in .NET?User gives
importance to the way your application collects data and displays data
on need. There are situations when same data has to be presented in multiple
representations at the same time.
When the data changes all these representations should reflect the change. This situation is common in stock market where you represent the stock fluctuations using a graph showing fluctuation of a stocks rate per day, per week and per month. In addition, you will also have its current rate getting updated in a table. How do you present your stock data in these many views? This is accomplished using observer pattern which takes care of presenting data in several different forms at the same time. You can implement observer pattern in .NET by defining interfaces similar to the ones shown below: public interface
Observer { Data which
you are going to present to User is termed as Subject and each of the
different representations of data will be referred as Observer. Each Observer
has to be registered using registerObserver method of the Subject and
when there is a change in data, all observers registered for the Subject
will be notified using sendNotification method of Observer. You can inherit
these two interfaces and present your data in different forms.
|