comp.lang.ada
 help / color / mirror / Atom feed
* ANNOUNCE: command pattern posted to ACM archives
@ 1999-03-14  0:00 Matthew Heaney
  0 siblings, 0 replies; only message in thread
From: Matthew Heaney @ 1999-03-14  0:00 UTC (permalink / raw)


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.

<http://www.acm.org/archives/patterns.html>

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
body:

subscribe patterns <your full name>

to the ACM mailing-list server.

<mailto:listserv@acm.org>

Matt

Command Pattern

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
scenario.

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
operation.


Implementation

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>





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-03-14  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-14  0:00 ANNOUNCE: command pattern posted to ACM archives Matthew Heaney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox