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-Thread: 103376,4a5bab72e3ac47fc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Dynamich Dispatching... Date: Mon, 4 Oct 2004 14:50:01 +0200 Message-ID: References: <18qpcb693v2zz$.1es3pcrwk4eiu$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de AbFQl84102Us4PeHsNPpYgaHy2LVAWJENk0U5nE1b6P9MSPBs= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:4657 Date: 2004-10-04T14:50:01+02:00 List-Id: On Mon, 04 Oct 2004 21:02:44 +1000, Brian May wrote: >>>>>> "Dmitry" == Dmitry A Kazakov writes: > > >> package Constructor is > >> function Create(Text: String; Radius: Integer) return Circle; > >> end Constructor ; > > Dmitry> You do not need a nested package here. > > , > section 1.4, recommends it. Actually, I don't understand why. Yes, it indeed reads strange: "If a class declares a function 'Create' returning an instance of a class, all the child classes inherit that operation. This can be hazardous, especially if the child class has more attributes than its parent (note: to make programmers pay attention, the inherited function will be abstract unless overridden). Indeed, the inherited 'Create' might not initialize these attributes." One *cannot* inherit Create, because, many tanks to Ada's designers, functions are covariant in their results. Quick checks shows it: package Foo is type X is tagged null record; function Create return X; type Y is new X with null record; -- Compile error, Y is not abstract, -- yet it does not override Create end Foo; One could treat Y's Create is as abstract, like in the quote, but where is any danger? Let Y be abstract, then it may have no instances of its own! Then if one really needs a contravariant result, then Create should be class-wide. It is as simple as: function Create return X'Class; One could use this variant for an object factory which decides which of X'Class to create. > There are other parts of this reference which seem dodgy though (at > least to me), so I am not sure how much you can rely on it. > > (Sections 1.2 and 7 really have me confused too). Yes. I have an impression that the document reflects some preliminary status of Ada.Finalization development. For example it talks about "void" objects etc. Just a guess. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de