std.pattern.. templated publisher subscriber pattern, adding events to collections

BLS windevguy at hotmail.de
Thu Jul 8 07:50:08 PDT 2010


@ Dmitry
Thanks for all the feedback Dmitry. Seems that we have similar projects 
in mind :) (maybe we can talk about the GUI project.. mine is similar to 
win32++ at http://sourceforge.net/projects/win32-framework/)
------------------------------------------------------------------------

However : Like you I would prefer to use something like ..

void delegate(const ref message) CallBack;
CallBack[] cb;
@Jakob
Adding some delegates to our list (D dyn. array) like in C# is a piece 
of cake..

But keep in  mind that we also need  removeObserver() in order to 
implement the Observer pattern.  And removing makes the difference.

The question is now :
How do we identify our Observer object in order to remove..
possible solutions :

1) passing the object instance to the mixin template. (as shown in my 
code) adding of course a : toHash() method.
2)
adding a GUID to the delegate..
3)
...

Dmitry, I think

YOUR :

final class Observable(Cont){
     Cont cont;
     //here goes your current Publisher stuff
     //...
     alias Cont!ElementType T;
     static if(__traits(compiles,cont.insert(T.init)))//some such ... 	
need to test if it has this method

SOLUTION

is very hackish. (Beside, like IsForwardRange!R )

IMHO a mixin template is a more clean solution.

BUT this requires that container/collection classes are not final.

Well, even for final classes there is still the option to implement a 
decorator pattern! But the decorator pattern makes code quite unreadable...

However, ATM I am thinking about how we can you use std.concurrent 
message passing stuff...

Finally
Would be nice if we can write a few LOC together! ??
bjoern
PS> Sure the Publisher/Observable mixin has to work for structs too.





More information about the Digitalmars-d-learn mailing list