- A Software Pattern is meant to be a generic
solution for a recurring problem. Then why does implementation of a pattern
vary?
- .Net/Java Event mechanism, MQ Series/MSMQ
messaging, COM Bidirectional communication mechanism Event-Sink etc all are
based on Observer pattern. What forces them to have different implementation?
- Is it not possible to create a generic
implementation of a pattern that is configurable and fits to all contexts?
- Can we consider patterns as complete solutions?
No says
Pattern
Oriented Software Architecture Volume 5: On Patterns and Pattern Languages
- A pattern differs from a specific solution to a
problem by a) Recursive nature of the problem b) Roles of components involved
in a pattern are strictly defined. But the organization of components to perform the role differs based on context.
- The structural , behavioral and internal
implementation variations of the pattern are influenced by
o
Context in which it is applied.
o Forces like a) Extensibility b) Testability c)
Language agnostic nature of components d) Performance etc.
o
Roles involved in patterns are universally
applicable, but implementation of those roles by different components varies
based on the real context.
- The main purpose of observer pattern is to
provide a mechanism for change propagation.
- Important roles involved in observer pattern are
a) Subject b) Observer.
o
Subject :-
Notifies registered dependents.
o Observer: - Dependents on Subject State.
Whenever state of subject changes , they should perform necessary actions.
- Variations in observer pattern
o
A single object might be an Observer in one
relationship and Subject in other.
o
A single subject may receive events from a
single subject or from multiple subjects.
o
A subject may be observed by single observer or
multiple observers.
o
Subject and Observers may be components in a
distributed system separated physically.
o
Subject and Observers may be components in an
Enterprise Integration Context.
Subject needs to be unaware of its Observers
and
Observers needs to be unaware of Subjects.
- Non functional requirements of the problem context like; performance etc
might also control the behavior. Example: - State propagation mechanism might
be push or pull. The data structures used might be influenced by the time
complexity of operations that will be performed.