Re: Observer Design Pattern



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



.



Relevant Pages

  • Re: !
    ... Because it seems to me that decoupling is all the Registrar gives you. ... The pattern is about dynamic substitution of Listeners based on solution context. ... One could just have a simple 1:* association and let Listener be added to the collection when it is instantiated. ... Specifically, it is not concerned with why the responsibility is needed or who created that need, so its coupling to external context is also reduced. ...
    (comp.object)
  • Re: Question observer design pattern .. more
    ... the Registrar is the Observer from the pattern but it is limited to ... not necessarily the Listener. ... If there is more than one message to dispatch, then the Registrar implementation gets more complicated because it has to match both {message ID, Listener reference}. ... there is a lot of wiggle room in the actual implementation of the pattern to accommodate varying degrees of complexity in the actual problem. ...
    (comp.object)
  • Re: Overwhelmed by choices of Design Patterns
    ... --- the client of the configurator most query the data out of the ... focusing that this is only a configurator that clients reads for its ... I am thinking of using Adapter PAttern. ... similarity from the adapter interface and the adaptee interface .. ...
    (comp.object)
  • Re: Win App Development Program Structure
    ... But I would stress more about the TDD. ... Also look into a particular design pattern called "Model View Presenter ... I would suggest reading a couple of books on design patterns. ... I have been developing custom apps ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Have you had good results with Trend Micro support?
    ... Unloading the Client ... was a suggestion to browse their support web, ... One of the clients also has a Server 2003 file server and the pattern ...
    (microsoft.public.windows.server.sbs)