Re: Observer Design Pattern
- From: "H. S. Lahman" <h.lahman@xxxxxxxxxxx>
- Date: Wed, 31 May 2006 15:04:15 GMT
Responding to Dmitry...
I am trying to implement my own Design Patterns Library.
I basically agree with Martin and Daniel T. Design patterns represent reusable conceptual models, not reusable implementations. If you look at the implementation examples for the GoF patterns you will note that they include code that is tailored to the problem in hand (i.e., the implementation code is not reusable for other problem contexts where the pattern might apply). Your issue with the type returned is an example of that.
Having said that, there are situations where one can modify the design patterns in the implementation so that they can service a fairly wide variety of problems in a generic fashion. For example, if one is only concerned about the notification aspects of Observer, then
[Subject]
| *
|
| R1
|
| announces state change to
| 1
[Registrar]
| 1
| registers with
|
| R2
|
| notifies
| *
[Client]
can be implemented with quite generic code in [Registrar] and a generic announce(<data packet>) and register (this, <Subject ID>) interface for any [Subject] or [Client] to use. Then the only application-specific code is the formatting of <data packet> and <Subject ID>, which [Registrar] doesn't need to understand.
While this example provides a generic infrastructure for broadcasting state changes to interested parties, it does not have the versatility of the full Observer pattern because there is no provision for direct interaction between [Client] and the observed [Subject].
However, if one views [Client] as the [Observer] in the pattern, one essentially does have the full pattern provided [Registrar] instantiates the relationship between [Client] and [Subject]. In effect this just delegates the pattern's registration responsibilities from [Subject] to [Registrar] so the registration infrastructure can be reused. The concrete subclasses of [Client] and [Service] would still have to be tailored to the specific problem in hand.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH
.
- References:
- Observer Design Pattern
- From: Krivenok Dmitry
- Observer Design Pattern
- Prev by Date: Re: Searching OO Associations with RDBMS Persistence Models
- Next by Date: Re: Observer Design Pattern
- Previous by thread: Re: Observer Design Pattern
- Next by thread: Head First Design Patterns
- Index(es):
Relevant Pages
|