comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: Ada 200X
Date: Thu, 05 Jun 2003 07:20:53 GMT
Date: 2003-06-05T07:20:53+00:00	[thread overview]
Message-ID: <3EDEEF2D.7000108@attbi.com> (raw)
In-Reply-To: bbk7oa$8t60e$1@ID-175126.news.dfncis.de

Vinzent Hoefler wrote:

 > This is where the "inherited" keyword comes handy...

I got to this point and suddenly realized why none of what Vinzent said 
was tracking.  Everything he said had nothing to do with Ada. In Ada 
most methods are inherited by default.

There is a special exception for functions which return a value of the 
tagged type which is being derived from.  In that case the function is 
inherited as an abstract operation, so that if you want to use it you 
must provide a body.  This is because you normally will need additional 
initialization code in the child.  If not:

       type Foo is tagged record
         ...
       end record;

       function Create(...) return Foo;
       procedure Print(F: in Foo);
       ...
       type Bar is new Foo with null record;
       -- at this point there is a Create which returns Bar, but it
       -- doesn't work.  There is an implicitly declared Print, and
       -- it can be called immediately.

       function Create(...) return Bar;
       ...
       function Create(...) return Bar is
       -- It would be nice to be able to say here:
       -- begin return Foo(Bar'(Create(...)); end Create;
       -- but the rules of the language don't allow downward conversions
       -- of tagged types, even if the child has no new fields. :-(

However, for the Print procedure I don't have to do anything special. 
It can be called on an object of type Bar by anyone who has a with 
clause for the package declaring Bar, even if there is no with clause 
for the package specifying the Print procedure.

So Vinzent if you try to reimplement this hierarchy in Ada you will 
learn a lot, including how easy it is.  But you will also find that some 
things which are classes in other languages are better handled as 
mix-ins in Ada.  Mix-ins are perfect for attributes and behavior that 
cut across a normal class hierarchy.  For example you could make 
radio_buttons a mix-in instead of a separate class.  Then for objects 
(windows) that need radio buttons you can mix in as many buttons as a 
particular window type or singleton instance needs.




  reply	other threads:[~2003-06-05  7:20 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-01 21:36 Ada 200X And838N
2003-06-02  2:22 ` Bobby D. Bryant
2003-06-02  4:20 ` Robert I. Eachus
2003-06-02 11:22   ` Larry Kilgallen
2003-06-02 14:09     ` Hyman Rosen
2003-06-02 14:23       ` Vinzent Hoefler
2003-06-02 14:59         ` Hyman Rosen
2003-06-02 15:04           ` Vinzent Hoefler
2003-06-02 15:18             ` Bill Findlay
2003-06-02 15:32               ` Larry Kilgallen
2003-06-02 15:41               ` Vinzent Hoefler
2003-06-02 15:07           ` Larry Kilgallen
2003-06-02 15:04         ` Larry Kilgallen
2003-06-02 14:23     ` Robert I. Eachus
2003-06-02 14:31       ` Vinzent Hoefler
2003-06-02 15:05         ` Larry Kilgallen
2003-06-02 15:06         ` Hyman Rosen
2003-06-02 21:05         ` Robert I. Eachus
2003-06-02 22:59           ` Larry Kilgallen
2003-06-03  4:07             ` Robert I. Eachus
2003-06-03  7:52           ` Jean-Pierre Rosen
2003-06-03  9:09           ` Vinzent Hoefler
2003-06-03 14:54             ` Robert I. Eachus
2003-06-04  7:38               ` Vinzent Hoefler
2003-06-05  7:20                 ` Robert I. Eachus [this message]
2003-06-02  5:36 ` Wesley Groleau
2003-06-02  8:02 ` Preben Randhol
2003-06-02 10:50 ` Georg Bauhaus
2003-06-03  2:29 ` Steve
2003-06-03  2:45 ` Gautier Write-only
2003-06-03  8:38   ` Vinzent Hoefler
2003-06-03 11:48   ` Preben Randhol
2003-06-03 12:14     ` Lutz Donnerhacke
2003-06-03 12:35       ` Preben Randhol
2003-06-07 21:16       ` Craig Carey
2003-06-08 11:14         ` Martin Dowie
2003-06-09 14:07           ` Craig Carey
2003-06-13 14:20             ` Matthew Heaney
2003-06-13 14:00         ` Matthew Heaney
2003-06-03 17:24     ` Robert A Duff
2003-06-03 17:45       ` Preben Randhol
2003-06-03 17:48         ` Preben Randhol
2003-06-03 18:05           ` Vinzent Hoefler
2003-06-04 10:36             ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
2004-10-31  1:51 David Botton
2004-10-31  7:33 ` Martin Dowie
2004-10-31 18:59   ` Jeffrey Carter
2002-12-26 16:17 Ada 200x Adrian Hoe
2002-12-27 19:32 ` Randy Brukardt
2002-12-27 20:55   ` Robert A Duff
replies disabled

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