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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,76ec5d55630beb71 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-05 00:21:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail Message-ID: <3EDEEF2D.7000108@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada 200X References: <3EDAD07A.3010200@attbi.com> <3EDB5DBE.4070807@attbi.com> <3EDBBC18.6080103@attbi.com> <3EDCB68D.9070802@attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1054797653 24.62.164.137 (Thu, 05 Jun 2003 07:20:53 GMT) NNTP-Posting-Date: Thu, 05 Jun 2003 07:20:53 GMT Organization: AT&T Broadband Date: Thu, 05 Jun 2003 07:20:53 GMT Xref: archiver1.google.com comp.lang.ada:38658 Date: 2003-06-05T07:20:53+00:00 List-Id: 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.