I have prepared a short article on how to implement the command pattern
in Ada95, and posted it to the ACM patterns archive. The introduction
of the article appears below.
I've been slowly converting the C++ examples in the book Design Patterns
to Ada95. In each article I discuss the pattern, explain how to
implement it in Ada, and explore various idioms and language features.
A complete, working example with all the code is included.
You can subscribe to the patterns list by sending a message with the
subscribe patterns <your full name>
to the ACM mailing-list server.
<mailto:[log in to unmask]>
Command objects manage the processing that occurs when a user
manipulates the application in some way.
Objectifying a command admits all kinds of interesting possibilities.
You can put the command on a stack to implement undo and redo, or write
the command to disk to implement record/playback.
You don't even have to execute the command right away. In a simulation
each command has a scenario time. You put the command on a queue and
execute the command later, when the simulation reaches that point in the
In the example here, a menu-based application manages a group of open
documents. Each menu item contains a command object, bound at creation
time to a document object, which when executed calls a document
In C++, you can bind a command to a document by passing the document as
a parameter in the constructor for the command.
For binding one object to another in Ada95 we use access discriminants,
a language feature created specifically for this purpose. The advantage
of this approach over C++ constructors is that the language guarantees
that a dangling reference cannot occur.
<rest of article and code snipped>