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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,436e4ce138981b82 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-10 10:07:22 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!wn13feed!worldnet.att.net!216.196.106.140!border1.nntp.sjc.giganews.com!nntp.giganews.com!local1.nntp.sjc.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 10 Mar 2004 12:07:17 -0600 Date: Wed, 10 Mar 2004 13:07:17 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: abstract sub programs overriding References: <1078776213.376775@master.nyc.kbcfp.com> <1078839257.157439@master.nyc.kbcfp.com> <5cmr40t76va200betf07b7bd6er05ltto9@4ax.com> <1078845298.702789@master.nyc.kbcfp.com> <0ipr40thtf86b520a0qdi003aj87gtuhd4@4ax.com> <1078849973.701176@master.nyc.kbcfp.com> <1078924150.268074@master.nyc.kbcfp.com> <1078934469.744922@master.nyc.kbcfp.com> In-Reply-To: <1078934469.744922@master.nyc.kbcfp.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.147.77.160 X-Trace: sv3-XPYrA3m2kP0iBLHBkrQCdRHl6E22JEePdGw0PsPX7KsORevvoD0j16DxBryAppsvANQ9INXK5UQNbvE!2ym7sZlXqmdRcEloVEF+rlgSf0bW8U1ak52N9t/ZeF4/YnXQApkXAIaWy0pJxg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:6215 Date: 2004-03-10T13:07:17-05:00 List-Id: Hyman Rosen wrote: > I don't think you're answering to the issue at hand. The first question > is, if you have a class hierarchy where each class has an Initialize > defined for itself, and you create an object of the most derived class, > does Ada arrange for all of the Initialize procedures to be called, or > does each Initialize need to explicitly invoke its parent? The usual in Ada is to define any tagged type that has a private part such that it always gets initialized correctly, independent of whether a child class is created, with or without an explicit Initialize. It is also normal to insure that even if the Initialize procedure is called twice, there is no problem. Doing this correctly for Finalization is a bit more complex, because of the possibility of an exception during the creation, Initialize call, or Finalize for a child type. > The second > question, or observation, is that however it's called, a parent Initialize > can view-convert its object to classwide type and call a dispatching > procedure on it. This means that a derived class procedure might be > called from a parent Initialize before its own Initialize has prepared > the class. I'm not saying this is common, but DK was saying that this > couldn't happen in Ada, and I'm saying that it can. DK is right, in fact I have trouble figuring out which problem you are trying to create here. A view conversion can convert to a parent type, but to down convert to a type, the object has to be of that type (or a descendant of it). So what you are imagining sounds like an explicit call to Parent.Initialize(Parent_Type(Child_Object)), where Parent.Initialize then makes a dispatching call to some other operation of the child type. First, let me say, DON'T DO THAT. It will be very difficult to design real examples where you don't raise an exception. Now, as it turns out the only way this could cause a problem is if Child.Initialize had a nested call to Parent.Initialize before the Initialization of the Child specific fields was completed. Again, you could do that, but you should not for other reasons. It is much more common, however, for such a call to be done for only the parent part of the object, for example when creating a child object using an aggregate. There is no problem in that case, because the (implicit) call to the parent Initialize is for an object of the parent type. Also, as I said above, and as Dmitry said, there is a two-stage initialization process, and it is normal in Ada to insure that all fields where it matters are intialized to some default value in the first stage of initialization. So if you really want to, you could probably design some example program where you violate all three of these principles, and it causes a problem. But it is much easier to use Unchecked_Conversion to get to the same place. -- Robert I. Eachus "The only thing necessary for the triumph of evil is for good men to do nothing." --Edmund Burke