comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: abstract sub programs overriding
Date: Wed, 10 Mar 2004 13:07:17 -0500
Date: 2004-03-10T13:07:17-05:00	[thread overview]
Message-ID: <R5CdnWqtCoDLxNLdRVn-uA@comcast.com> (raw)
In-Reply-To: <1078934469.744922@master.nyc.kbcfp.com>

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




  reply	other threads:[~2004-03-10 18:07 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-02 19:01 abstract sub programs overriding Evangelista Sami
2004-03-03  1:43 ` Stephen Leake
2004-03-05 15:02   ` Evangelista Sami
2004-03-05 16:15     ` Marius Amado Alves
2004-03-08 18:54       ` Adam Beneschan
2004-03-08 23:42         ` Marius Amado Alves
2004-03-05 16:26     ` Marius Amado Alves
2004-03-06  9:31       ` Simon Wright
2004-03-06 15:18         ` Evangelista Sami
2004-03-06 19:09           ` Marius Amado Alves
2004-03-07 12:35             ` Simon Wright
2004-03-07 13:39               ` Marius Amado Alves
2004-03-08 19:08               ` Adam Beneschan
2004-03-08 20:03                 ` Hyman Rosen
2004-03-09  8:51                   ` Dmitry A. Kazakov
2004-03-09 13:34                     ` Hyman Rosen
2004-03-09 14:49                       ` Dmitry A. Kazakov
2004-03-09 15:14                         ` Hyman Rosen
2004-03-09 15:56                           ` Dmitry A. Kazakov
2004-03-09 16:32                             ` Hyman Rosen
2004-03-10  9:32                               ` Dmitry A. Kazakov
2004-03-10 13:08                                 ` Hyman Rosen
2004-03-10 14:58                                   ` Robert I. Eachus
2004-03-10 16:00                                     ` Hyman Rosen
2004-03-10 18:07                                       ` Robert I. Eachus [this message]
2004-03-10 20:04                                         ` Hyman Rosen
2004-03-11  2:43                                           ` Robert I. Eachus
2004-03-11 13:55                                             ` Hyman Rosen
2004-03-12 23:02                                               ` Robert I. Eachus
2004-03-14 21:33                                                 ` Hyman Rosen
2004-03-15  5:59                                                   ` Robert I. Eachus
2004-03-15 14:39                                                     ` Hyman Rosen
2004-03-16 16:16                                                       ` Robert I. Eachus
2004-03-16 16:51                                                         ` Hyman Rosen
2004-03-16 19:54                                                         ` Hyman Rosen
2004-03-16 23:16                                                           ` Randy Brukardt
2004-03-17  1:54                                                           ` Robert I. Eachus
2004-03-16 23:14                                                         ` Randy Brukardt
2004-03-17  2:43                                                           ` Robert I. Eachus
2004-03-17 17:40                                                             ` Randy Brukardt
2004-03-18  2:39                                                               ` Robert I. Eachus
2004-03-18  5:57                                                                 ` Randy Brukardt
2004-03-18 15:03                                                                   ` Hyman Rosen
2004-03-18 20:32                                                                     ` Randy Brukardt
2004-03-19  3:59                                                                       ` Hyman Rosen
2004-03-19 19:37                                                                         ` Randy Brukardt
2004-03-16  6:00                                               ` Randy Brukardt
2004-03-11 10:09                                   ` Dmitry A. Kazakov
2004-03-11 14:10                                     ` Hyman Rosen
2004-03-11 14:59                                       ` Dmitry A. Kazakov
2004-03-11 15:40                                         ` Hyman Rosen
2004-03-11 16:28                                           ` Dmitry A. Kazakov
2004-03-11 17:26                                             ` Hyman Rosen
2004-03-12  8:53                                               ` Dmitry A. Kazakov
2004-03-12 13:09                                                 ` Hyman Rosen
2004-03-12 14:00                                                   ` Dmitry A. Kazakov
2004-03-12 14:56                                                     ` Hyman Rosen
2004-03-12 18:19                                                       ` Dmitry A. Kazakov
2004-03-12 18:34                                                         ` Hyman Rosen
2004-03-12 20:05                                                           ` Georg Bauhaus
2004-03-13 10:12                                                           ` Dmitry A. Kazakov
2004-03-12 18:07                                               ` Robert I. Eachus
2004-03-10 15:51                 ` Evangelista Sami
2004-03-11  1:38                   ` Dan Eilers
2004-03-06 23:20     ` Dan Eilers
2004-03-03 12:00 ` Marius Amado Alves
2004-03-13  7:51 ` Simon Wright
replies disabled

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