You missed his point.

More generally, no overridable method should be so critical to an object
that it's having never been called should cause the object not to function.
If it is that critical, that it must not be overridable.

Let me ask a question:  What is the point of making an method whose
responsibility is to initialize the object be virtual?  It is so that the
initialization of the object can be customized.  You can't say "The
initialization is customizable, but don't you dare customize it"

So break the init into critical and non-critical, with the non-critical
being virtal.

I'm glad this issue was brought up, because it is an important object design
topic.  I had never honestly thought about it until now, but I can see now
it is a bad design.  As a science project, I wonder if anyone could check
other C++ compilers to see if this is a implementation thing or not.

John

-----Original Message-----
From: Stefan Holdermans [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 19, 2003 1:32 PM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Partially constructed objects in C#


Robert,

>I concur with a previous respondent who mentioned that it's
>simply a bad idea to call a potentially-overridden method from
>within your constructor, if that method does something
>critical to the object construction.

Simply stating that is not enough, I'm afraid. The point is that,
appearantly, you can't just call the virtual method from the constructor for
it's not reliable: it might, for instance, try to access some uninitialzed
members. Being critical for object construction does not make such a call
more reliable...

Regards,

Stefan

Reply via email to