Command
represents any generic operation and is often combined
with other such objects in a sequence. This is the foundation for
implementations of pipelines, logging, undo stacks, etc, according
to the Command design pattern. Since Command
is virtual, it
cannot be constructed directly. Rather, one should construct an
instance of a concrete derivative, like Operation
or Protocol
.
Command
for new
implementations of the Command design pattern. There are a number of generics for which a Command
derivative
should provide methods:
displayName(object)
: Gets the display name of the
command, i.e., the name displayed in a user interface. The default
implementation returns the class name. A Command
may
provide other visual attributes; the display name is considered
fundamental for integration with user interfaces.
widget(object, ...)
: Creates a widget for viewing and
controlling this object. No default implementation.
rev(object)
: Returns a Command
that performs
the opposite action, i.e., to undo an operation. This will not
always be possible, so it is acceptable for a subclass to leave
this unimplemented.
active(object)
: Gets whether the command is
considered active. This is meant for temporarily disabling or
enabling a command without removing it completely from, e.g., a
pipeline or GUI menu. No default implementation.
Of course, a Command
implementation also needs a method that
executes the command. The signature for such a function highly depends
on the nature of the command, so the generic depends on the class.