From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 16 Jul 93 15:58:44 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: OO Preprocessor for Ada Message-ID: List-Id: In article <15JUL199315464091@cl2.cl.uh.edu> riley@cl2.cl.uh.edu (JOHN D. RILEY ) writes: > I think your suggestion is this: > Package X is > type object is ?whatever?; > Procedure OP1 (Q : object); > end X; > Don't I still need to pass the object as a parameter? If you care about this, the Ada solution has always been to use generic package instantiations as objects: generic package X is procedure OP1; private type object is -- or can appear in the package body, or the state -- variable can be declared separately instead of -- as a record type... package Y is new X; ... Y.OP1; ... The rules about where tagged types can be declared in Ada 9X will limit where instantiations can appear if they include tagged types, but none of this depends on tagged types. (It might be nice to have generic instances as first class objects, but that is a different discussion. In Ada 83 you can do it with task types, but the run-time overhead is huge.) also suppose I have: Package Y is type object is ?whomever?; Procedure OP_A (Q : object); end Y; > now I encounter class Z which is logically the union of X and Y. > I would like to do something like: > Package Z is > COMBINES (X,Y); > ..... > end Z; generic package Z is procedure OP1; procedure OP_A; end Z; (Note that in this case you normally don't want to use the new Ada 9X generic package parameters as they simplify declaring Z at the cost of extra work at instatiation time.) with X,Y; package body Z is package My_X is new X; package My_Y is new Y; procedure OP1 renames My_X.OP1; procedure OP_A renames My_Y.OP_A; -- new feature in Ada 9X. In Ada 83 you have to use call-throughs. end Z; > so now I could call both Z.OP1 and Z.OP_A to act on an object of class Z. All done... I have designed and written several applications using this style of OOP in Ada 83. It works very nicely for simulations where you have a small number of objects which are individualized through generic parameters. (The number of objects need not be constant.) Especially in Ada 83 though, it helps to have tools to automagically generate the bodies for packages which do call-throughs. (Steve Litvintchouk has some gnu emacs extensions that help a lot.) In Ada 9X both the package parameters and renaming as bodies will ease the pain a lot. (I'm also hoping that protected objects will provide a better way of making these object types first class.) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...