Observer Pattern
Shahriar Iqbal Chowdhury & Monjurul Habib

       Code Name: Remington



     http://www.facebook.com/groups/netter/
Observer Defined
• He's a silent guardian. A watchful protector. A Dark Knight.
Pattern States
  Define a one-to-many dependency between objects so that when one object changes
             state, all its dependents are notified and updated automatically
Applicability
• When an abstraction has two aspects, one dependent on the other.
  Encapsulating these aspects in separate objects lets you vary and
  reuse them independently.

• When a change to one object requires changing others, and you don't
  know how many objects need to be changed.

• When an object should be able to notify other objects without
  making assumptions about who these objects are. In other words,
  you don't want these objects tightly coupled.
Observer @ Gotham City
Example (Notify on Withdrawal)
Subject
Concrete
 Subject
Observer
Concrete
Observer




Concrete
Observer
Invoke
Advantages

1. Eliminates dependencies
2. Increases extensibility
3. Improves testability
Observer & .NET framework
• Model View Controller Pattern - The observer pattern is used in the
  model view controller (MVC) architectural pattern. In MVC the this
  pattern is used to decouple the model from the view. View represents
  the Observer and the model is the Observable object.

• The introduction of delegates and events provides a new and
  powerful means of implementing the Observer pattern

Observer pattern

  • 1.
    Observer Pattern Shahriar IqbalChowdhury & Monjurul Habib Code Name: Remington http://www.facebook.com/groups/netter/
  • 2.
    Observer Defined • He'sa silent guardian. A watchful protector. A Dark Knight.
  • 3.
    Pattern States Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically
  • 4.
    Applicability • When anabstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently. • When a change to one object requires changing others, and you don't know how many objects need to be changed. • When an object should be able to notify other objects without making assumptions about who these objects are. In other words, you don't want these objects tightly coupled.
  • 5.
  • 6.
    Example (Notify onWithdrawal)
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
    Advantages 1. Eliminates dependencies 2.Increases extensibility 3. Improves testability
  • 13.
    Observer & .NETframework • Model View Controller Pattern - The observer pattern is used in the model view controller (MVC) architectural pattern. In MVC the this pattern is used to decouple the model from the view. View represents the Observer and the model is the Observable object. • The introduction of delegates and events provides a new and powerful means of implementing the Observer pattern