From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,eb69d5c7a426effd,start X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: ANNOUNCE: command pattern posted to ACM archives Date: 1999/03/14 Message-ID: #1/1 X-Deja-AN: 454690475 Sender: matt@mheaney.ni.net NNTP-Posting-Date: Sat, 13 Mar 1999 16:24:12 PDT Newsgroups: comp.lang.ada Date: 1999-03-14T00:00:00+00:00 List-Id: 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 body: subscribe patterns to the ACM mailing-list server. 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.