Intent:
- Define one-to-many dependency between objects so that when one objects changes state, all its dependents are notified and updated Automatically
- Dependents, Publish-Subscribe, Model-View
- When an abstraction has two aspects, one dependent on the other.
- When a change to one object requires changing others without being coupled.
Participants:
Subject
- knows its observers.
- any number of Observer objects may observe a subject.
- provides an interface for attaching and detaching Observer objects.
- defines an updating interface for objects that should be notified of changes in a subject.
- stores state of interest to ConcreteObserver objects.
- sends a notification to its observers when its state changes.
- maintains a reference to a ConcreteSubject object.
- stores state that should stay consistent with the subject's.
- implementes the Observer updating interface to keep its state consistent with the subject's.
- ConcreteSubject notifies its observers whenever a change occurs that could make its observers' state inconsistent with its own.
- After being informed of a change in the concrete subject, a ConcreteObserver object may query the subject for information.
- ConcreteObserver uses this information to reconcile its state with that of the subject.
- Abstract coupling between Subject and Observer.
- Support for broadcast communication.
- Unexpected updates.
Document - View architecture
- Document is responsible for data
- View is responsible for representing data
- There can be multiple type of document and view
- Any view can be interested in tracking changes in any document
No comments:
Post a Comment