[OT] Re: Signals and Slots in D

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Sep 28 20:58:41 PDT 2006


All this Signals&Slots business (which I also admit to having zero experience with) makes 
me think of the Actions concept I worked into my hypothetical GUI library, based on a 
similar concept found (with incomplete implementation, last I checked) in Java's Swing 
GUI.  An 'Action' is an object representing a behavior (or, well, "action" :)) of the 
program, and has three faculties: storage of metadata, such as a name, associated 
resources, etc; generation of Presenters, such as toolbar buttons and menu items; binding 
to Performers -- callbacks that do the work of the Action.  Some snips to (hopefully) make 
it clearer:

# // bind this.open(ActionContext) to an appropriate Action
# Action["OpenFile"].append(&open);

Note that we need only refer to the Action instance by its name, and note also the Context 
class which is sent as the only parameter.  This would encapsulate any additional data 
needed by the Performer, and can also be subclassed for custom data.  (In theory, anyhow.)

# // retrieve a menu item Presenter for an Action
# auto item = Action["SaveAs"].presenter(new MenuItem);

Surely also self-explanatory.

In addition to the .append() method for adding Performers, there is a .prepend() -- for 
completion, but could be useful -- a .clear() which unbinds all Performers, and a .set() 
which is the same as clearing and then appending.  Actions (in my hypothetical GUI, mind 
you) would be triggered by component objects, usually in response to an event from the 
underlying system's GUI concept.  (Messages in Windows, for example.)  All the library 
user's code need do is bind Performers to Actions, and generate appropriate components by 
asking Actions for their Presenters.  The program then, essentially, runs itself.

How does this idea relate to Signals&Slots?  I really want to understand what exactly 
makes S&S so valuable.  Is it essentially just a standard for convenience?  (Which would 
be a bad thing, neccessarily, but that's all I can figure it to be.)  Or does it 
inherently open up some new capability I'm not aware of?

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list