Pattern for Command Enabling? 
Author Message
 Pattern for Command Enabling?

Does anyone know of a design pattern that describes a good implementation
of a way to properly enable and disable application functions based on
whatever criteria?

This seems like something that everyone would need to do at some opint in
their Smalltalk life and I was wanting to try and keep all of that behavior
from too much cluttering my controllers.

Any suggestions are appreciated.

 - Chris Muller



Wed, 18 Jun 1902 08:00:00 GMT  
 Pattern for Command Enabling?

Quote:

>Does anyone know of a design pattern that describes a good implementation
>of a way to properly enable and disable application functions based on
>whatever criteria?

>This seems like something that everyone would need to do at some opint in
>their Smalltalk life and I was wanting to try and keep all of that behavior
>from too much cluttering my controllers.

You clearly want to isolate the logic for enabling and disabling from the
domain logic and other UI logic, and to keep it as close to the commands as
possible. I normally use one of two approaches
  1) Attach a block/message send to the command
  2) Have a method to maintain the correct state for all commands.

An example of the first pattern is the menus in Envy. When building e.g. a
VisualAge CwMenu you can specify an enable block for each item. When the menu
is invoked, the block is run for each item and it's state set appropriately.
This is very nice, and the only major gotcha is to ensure that the blocks run
very quickly, because many of them will be invoked each time the menu is
displayed.

An example of the second would be to provide an "update" method in a
VisualWorks applicationModel. Whenever something happens to force a UI update,
you would run this method. It would in general update the UI, and specifically
enable or disable widgets depending on the appropriate conditions.

Adding another level of indirection on this would have command
objects and associate the conditions with the commands. Then, whatever did the
enabling or disabling would simply ask the appropriate command its state. I'm
not a big fan of command objects, so I don't tend to do this, but it would be
a quite reasonable approach.

--

The Object People               http://www.objectpeople.com                  
613.225.8812(v) 613.225.5943(f) Your Smalltalk & Java Experts

Skinheads for Smalltalk.



Wed, 18 Jun 1902 08:00:00 GMT  
 Pattern for Command Enabling?

Quote:


> : Does anyone know of a design pattern that describes a good implementation
> : of a way to properly enable and disable application functions based on
> : whatever criteria?

> Commands can often be grouped by some criteria. Then they can be enabled
> and disabled by group when this makes sense. These groups are often
> similar to, or related to, "modes" in a user interface. So however you
> handle modes of one kind or another, enabling a mode can be seen as also
> enabling the "visibility" of a group of commands. Finding a command can be
> seen as similar to finding a file in a search path.

The above is good advice, but you can take it even farther.  Think about
the commands your system will accept at any given time and the
interpretation that the system will take of them at that time.  This is
in some sense a definition of a "command" state.  If, after a particular
command has been executed, something has changed, i.e., some command(s)
are now acceptable/unacceptable, or some commands are interpreted
differently, we can think of the system as being in a new state, where
the transition from the old state to the new state was caused by the
command previously entered.

What this means is that you can model command processing as a state
machine.  At any time, all commands can be accepted by the machine, but
some will be carried out, some will be ignored and some will have errors
associated with them.  In other words, each individual command is really
a polymorphic operation; the actual command which is invoked will be the
command in the object corresponding to the system's current state.

Let me clarify this:

suppose our system has three commands, x, y, z.  In state 1, only x is
allowed (x is like a log in).  State 2 happens after x is entered.
Here, y and z are valid, but x is ignored. If z is entered (like a log
out) we return to state 1.

Define a class command interpreter with part command and operation set
state.

We now define the superclass command to have 3 operations , x, y and z.

subclass command1 defines operation x to be the log on, and operation y
and z to do nothing.

subclass command2 defines operations y and z, but does nothing upon x.

In the command1.x operation the command interpreter is told to reset its
current state to 2.  This causes the interpreter to instantiate an
object of type command2 and put it in part state.

in the command2.z operation the command interpreter is told to reset its
state to 1.  This causes the interpreter to change part to an object of
class command1.

Every time the interpreter gets a command it dispatches it to the
appropriate operation in its current part.  For example, if the part is
currently command1, an x will result in a log-in, if the part is
currently command2, x will be ignored.

An example of this is in the GoF pattern state.  Try it, it's really
quite effective.



Wed, 18 Jun 1902 08:00:00 GMT  
 Pattern for Command Enabling?

: Does anyone know of a design pattern that describes a good implementation
: of a way to properly enable and disable application functions based on
: whatever criteria?

This may be too far out in left field for practical purposes, but an
interesting paper to read about this topic is Henry Leiberman's "There's
more to menus than meets the eye."  I cannot remember where it was
published. It may be available from his web pages at MIT. I don't know.

If you are familiar with the Symbolics Genera operating system, or with
the Common Lisp Interface Manager (CLIM), it is a take off from there.
Sort of a "least fixed point" of CLIM.

--
Patrick Logan


    http://www.gemstone.com



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. When to enable Redo command?

2. CLIM command-enabled question

3. Does anyone know how to enable command repetition using the arrow keys on tclsh for UNIX

4. (Simple) command pattern in Eiffel

5. ANNOUNCE: command pattern posted to ACM archives

6. command pattern/framework in python?

7. commands that take ?pattern?

8. How to make a command run again and again until it sees a certain pattern

9. What *is* pattern in option add command?

10. pattern,pattern problem

11. Pattern Definition GREP with Pattern Editing for MSDOS

12. How to write filesearch with begin-pattern till end-pattern

 

 
Powered by phpBB® Forum Software