Article View: borland.public.jbuilder.java.language
Article #14889Re: Illogical constructor behaviour?
From: Tom.Eugelink
Date: Mon, 26 Jul 1999 00:00
Date: Mon, 26 Jul 1999 00:00
60 lines
3646 bytes
3646 bytes
Hm hm. Now that is starting to make sense. I totally agree with 1 not being a fine solution, so we can stike that one. The last one, 2b, I do not agree with: I am making a difference in initialization by placing the initialisation code outside of the constructor. So then it is defendable to also treat it differently. 2a, however, I agree, is a hassle: it is just as likely to have the situation reversed (where the child is depending in the parent) as it is to get my situation... However, looking at possible solutions, it appears that "your" situation is easily solved by placing the parent dependant initialization code not in the data definition area, but after the super() call in the constructor. This would ensure proper initialization of the parent prior to local initialisation The other way around is not solved as easily, because I cannot place initialisation code BEFORE the super(). So executing initialisation statements contained in the data definition area before the constructor is called, would get you "best of both methods". Basically this is the same as placing initialization code before the super(), and letting the programmer decide what initialzation code is parent dependant. (Oh oh, treading on eggs here ;-) Both, or even all, methods of initialization are well-defined (as long as someone took some time to think about it ;-), and whatever falls outside of this method could be considered a "programming caveat". So because this one approach was chosen, does not mean it is better by default, it should be better for a reason... (And I hate people who end an agrument with "this is what the standard says" ;-) Tom On 22 Jul 1999 10:09:31 +0200, Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> wrote: >1) Class files would have a data segment of "defaults" in addition to > the already present String heap. Here you would only be able to > initialize with primitive type constants - very limiting. >2) Calling the super constructor would be postponed until directly > declared fields had been initialized. This has two major drawbacks: > > * The initialization code cannot invoke - directly or indirectly - > non-static methods or fields in the superclass, since those > aspects of the object aren't in a "proper" state. > > * If you allow initialization to happen both before and after > invocation of the superclass' constructor, you start to > differentiate between initializations that occur outside from > those declared inside the constructor method. > >I vastly prefer the current situation, where the behaviour of >constructors are well-defined and known to the programmers. That the >programmer should avoid invoking non-final/private methods in a >contructor can be thought of as a programming caveat. >
Technical Details
Message-ID:
<379c0a08.3224616@forums.inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3789a7ea.1163072@forums.inprise.com> <uzp1241hv.fsf@sds.no> <378adee2.3105084@forums.inprise.com> <uhfn8aph8.fsf@sds.no> <378c7224.5379925@forums.inprise.com> <MPG.11f734ffaf88e14d989683@forums.inprise.com> <3792d12a.4122557@forums.inprise.com> <upv1osstw.fsf@sds.no> <379424a2.91026959@forums.inprise.com> <u1ze3g3bj.fsf@sds.no> <3796c981.4100195@forums.inprise.com> <uogh59kck.fsf@sds.no>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.Eugelink@OVSoftware.com Subject: Re: Illogical constructor behaviour? Date: 1999/07/26 Message-ID: <379c0a08.3224616@forums.inprise.com> X-Deja-AN: 505293887 References: <3789a7ea.1163072@forums.inprise.com> <uzp1241hv.fsf@sds.no> <378adee2.3105084@forums.inprise.com> <uhfn8aph8.fsf@sds.no> <378c7224.5379925@forums.inprise.com> <MPG.11f734ffaf88e14d989683@forums.inprise.com> <3792d12a.4122557@forums.inprise.com> <upv1osstw.fsf@sds.no> <379424a2.91026959@forums.inprise.com> <u1ze3g3bj.fsf@sds.no> <3796c981.4100195@forums.inprise.com> <uogh59kck.fsf@sds.no> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language