Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #5769
| From | "Qu0ll" <Qu0llSixFour@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Automatic linking of related objects in constructor |
| Date | 2011-06-29 19:56 +1000 |
| Message-ID | <eYKdnUijTfibapfTnZ2dnUVZ_uadnZ2d@westnet.com.au> (permalink) |
Suppose you have class A which contains a list of objects of class B and that the constructor for B takes in a reference to the A object which is to include it in said list. Is it safe to make a call to A's method addB(B b) in that B constructor passing in "this"? I have heard that it's bad practice to "leak" a reference to an object from within its own constructor because it may be in an invalid state. If not, how else can I automatically add the B object to the list in A without forcing the client programmer to explicitly call addB() given that they have already passed in the B as an argument? And loving it, -Qu0ll (Rare, not extinct) _________________________________________________ Qu0llSixFour@gmail.com [Replace the "SixFour" with numbers to email me]
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar
Automatic linking of related objects in constructor "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-06-29 19:56 +1000
Re: Automatic linking of related objects in constructor "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-06-29 19:58 +1000
Re: Automatic linking of related objects in constructor Lew <noone@lewscanon.com> - 2011-06-29 07:28 -0400
Re: Automatic linking of related objects in constructor Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-29 08:29 -0400
Re: Automatic linking of related objects in constructor Tom Anderson <twic@urchin.earth.li> - 2011-06-30 22:51 +0100
Re: Automatic linking of related objects in constructor supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-30 18:23 -0400
Re: Automatic linking of related objects in constructor markspace <-@.> - 2011-06-29 09:17 -0700
Re: Automatic linking of related objects in constructor supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-29 19:58 -0400
csiph-web