comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@mitre-bedford.arpa  (Robert I. Eachus)
Subject: Re: OO Preprocessor for Ada
Date: 16 Jul 93 15:58:44 GMT	[thread overview]
Message-ID: <EACHUS.93Jul16105844@spectre.mitre.org> (raw)

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

             reply	other threads:[~1993-07-16 15:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-07-16 15:58 Robert I. Eachus [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-08-19 19:03 OO Preprocessor for Ada cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!vixen.cso.u
1993-08-19 10:36 Graham Matthews
1993-08-18 22:30 agate!spool.mu.edu!sol.ctr.columbia.edu!emory!europa.eng.gtefsd.com!darwi
1993-08-18 20:31 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!vixen.cso.u
1993-08-18 19:22 cis.ohio-state.edu!math.ohio-state.edu!darwin.sura.net!source.asset.com!c
1993-07-21 14:41 David Emery
1993-07-19 14:32 news.cnri.reston.va.us!newsserver.jvnc.net!louie!balin.cis.udel.edu!carro
1993-07-15 14:46 Tucker Taft
1993-07-15 13:02 dog.ee.lbl.gov!overload.lbl.gov!agate!howland.reston.ans.net!math.ohio-st
replies disabled

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