All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface uhr.core.role.StateCommandable

public interface StateCommandable
This interface allows the state of an class to be changed by commands. Means are avaiable for publishing information about the state machine, allowing the designer, user and other classes to better understand things.

For example one may wish to control the lifecycle of parts, relieving them of that confusing burden and allowing a part framework to achieve higher reuse.

One planned use for this is to allow users to right click on a System Tree part node. The context menu is dynamically built using the current state and StateCommandableInfo. The current state is mentioned and all commands are listed. Those commands not allowable at this time are disabled. The part designer can add unit tests, what ifs, etc for development use, and remove them later.

Special thanks to Wayne Allen for suggesting the default command trick, which he has used in his system designs. He has used this to cycle from an object's initial to terminal state and other things. We could use it to be the default command for a part, such as what happens when a part is double clicked.


Method Index

 o doStateCommand(String)
The class should perform the command if its present state allows it.
 o getCurrentState()
Returns the current state, which is never null.
 o getStateCommandableInfo()
Returns information about the StateCommandable's business rules related to its state transition table.

Methods

 o doStateCommand
 public abstract void doStateCommand(String command)
The class should perform the command if its present state allows it.

Parameters:
command - the command to perform. It must be in the published list of commands available.
Throws: IllegalArgumentException
if unknown command.
Throws: IllegalStateException
if not in proper state to perform the command. Gee, this is precise. :-)
Throws: RuntimeException
or such if the command fails.
 o getCurrentState
 public abstract String getCurrentState()
Returns the current state, which is never null.

 o getStateCommandableInfo
 public abstract StateCommandableInfo getStateCommandableInfo()
Returns information about the StateCommandable's business rules related to its state transition table.

Since this is used for read only purposes, the info objects may be shared between StateCommandables. This is the Flyweight Pattern, and can modestly reduce resource requirements and increase startup speed.

Most StateCommandables will have static StateCommandableInfo. They are assumeed to return the same info instance each time with the identical data. This allows optimizing assumptions. If the info is dynamic then a new StateCommandableInfo should be returned each time.

Returns:
the information about the StateCommandable.

All Packages  Class Hierarchy  This Package  Previous  Next  Index