views:

50

answers:

1

In his book Extreme Programming Applied, Ken Auer casually mentions an Enabler pattern. Kent Beck also mentions it (at the very least in an email dated November 08, 2004), but I haven't been able to find any details in the usual places (Google, the wiki at c2.com, etc.)

Where can I find out more?

+3  A: 

The Enabler pattern is really just a variation of an Observer pattern. You set up observers on interesting parts of a system, creating Conditions. Enablers can then observe the conditions and enable/disable widgets.

E.g. when you load up a Window, you create Conditions that watch stuff like whether a list or combo box (or a model underneath the list or combo-box) has something selected. You can call it something like "somethingSelectedCondition". You then hook up enablers to widgets that are tied to one or more conditions (which you can and/or together... though typically you just want to and them together in practice).

I usually implement them by having a widget factory such that one of the parameters you pass in is an array of named conditions that, when anded together, enable/disable a widget. E.g.

widgetFactory.createButton(String buttonLabel, String methodActionName, String[] conditionNames)

The conditionNames will look up Conditions that are available in a some sort of HashMap, creat a CompositeCondition (which ANDs all of the observed boolean values of the conditions) and creates an Enabler which listens to the CompositeCondition and tells the created widget to enable/disable based on the underlying condition.

It sounds a bit complicated, but once you create the underlying infrastructure, a couple of lines of code wire up your conditions, and then the user interface is always in sync with the conditions.

I don't think I ever officially wrote up the Enabler pattern, or I'd just point you to a URL.

HTH,

Ken

This would seem to be the definitive answer! (FWIW, if you ever do write it up properly I'd love that URL. :-) ) Thanks also for a very helpful and interesting book.
Richard J Foster