Archive for the ‘Behavioral Patterns’ Category

Observer pattern is widely used in software development. You might be already using this pattern extensively but you may not be aware of it. Some of the real world examples are GUI Controls, Data Binding, File Watcher, Network Events and Model View Controller.

In this video I will discuss about 3 variations of this pattern

  1.        Traditional Observer Pattern – documented by Gang of four in design patterns book
  2.        Events and Delegates – Out of box Observer pattern in MS.Net Framework
  3.        IObservable<T> – new implementation of this pattern is added in Framework 4.0 Task Parallel Library

The Observer Design Pattern can be used whenever a subject has to be observed by one or more observers.

  •        It is a behavioral pattern
  •        It is also known as Publisher – Subscriber Pattern
  •        The observer 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.
  • Observer pattern is a way of notifying change to a number of classes

Observer.svg

Advertisements

As per the definition given by gang of four command pattern facilitates encapsulating a command request as an object – which means representing an action as an object

  1. This pattern helps us to persists a request/action in the form of an object
  2. The command pattern is a behavioral design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time
  3. It will allow you to have each of these actions as a separate object which you can save, retrieve and perform operations on the respective objects
  4. It’s basically designing our commands as objects

This pattern can be used everything from websites implementing complicated features like undo to implementing simple features like parsing command line arguments in console application.
I have used Job Life Cycle commands as an example to demonstrate command pattern. I hope that you would find it interesting and use it in your own applications.