Article View: borland.public.jbuilder.java.language
Article #15052Re: Illogical constructor behaviour?
From: Tom Davies
Date: Wed, 14 Jul 1999 00:00
Date: Wed, 14 Jul 1999 00:00
47 lines
2091 bytes
2091 bytes
Tom.Eugelink@OVSoftware.com wrote:
[snip]
> Oh, I understand what is going wrong and the logic behind it. But that
> still does not convince me that it is the best solution.
>
> Afterall, I did enter the constructor of the fireman class, so I feel
> that that is enough reason to have all instance variables not only
> allocated but also declared. I now had to resort to an if statement in
> each constructor checking the name of the class against a (hardcoded)
> value to see if I am at toplevel and can make the display call safely.
> (And that is coding I consider, eh, rude... ;-)
One benefit of the way things work now is that *all* the fireman code
(including whatever expressions are used to initialise fireman's
instance variables) knows that it has a fully initialised instance of
person to work with.
Rather than putting code which relies on derived classes being fully
constructed in the base class constructor, what about this sort of
solution:
abstract class Base {
public Base()
{
// just intialises base
}
protected void init(String arg)
{
// can assume object is fully built
}
}
final class Derived extends Base {
public Derived(String arg)
{
super();
// intialise derived here
init(arg);
}
}
Note that I differentiate between classes which are parents of derived
classes and classes which are leaves in the inheritance tree. This can
make things simpler.
Tom
Technical Details
Message-ID:
<378BCF99.61C8644@smartchat.net.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3789a7ea.1163072@forums.inprise.com> <uzp1241hv.fsf@sds.no> <378adee2.3105084@forums.inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,c150801d0979e255 X-Google-Attributes: gidf74b3,public From: Tom Davies <tom@smartchat.net.au> Subject: Re: Illogical constructor behaviour? Date: 1999/07/14 Message-ID: <378BCF99.61C8644@smartchat.net.au> X-Deja-AN: 500491669 Content-Transfer-Encoding: 7bit References: <3789a7ea.1163072@forums.inprise.com> <uzp1241hv.fsf@sds.no> <378adee2.3105084@forums.inprise.com> To: Tom.Eugelink@OVSoftware.com Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language