Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26227

Re: Object's properties changed

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail
NNTP-Posting-Date Sat, 12 Feb 2011 01:01:36 -0600
Date Sat, 12 Feb 2011 15:01:36 +0800
From Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com>
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: Object's properties changed
References <0c26a62d-08b7-4149-a36b-ec3d9e6e8804@o14g2000prb.googlegroups.com>
In-Reply-To <0c26a62d-08b7-4149-a36b-ec3d9e6e8804@o14g2000prb.googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Message-ID <d62dnUWFX6XMrcvQnZ2dnUVZ_tidnZ2d@posted.palinacquisition> (permalink)
Lines 29
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 219.74.123.211
X-Trace sv3-yx5KCR2cXOsi/JfXJ0vEJ3izL30CUdLaypEaMx5frKpVY3uM+UCWj1yf31Bk1bMjXxMyM+c8Ds5TpWk!s0EdkcV+G28XQIhrURvk6e8o3cz0Qy8Pw1HC21F+fPtKmHwsvFlMM4dzQvfGULkJNIvfkA0G9anR!QKUBUWMw+FdTCUagAK2wQ3pttFyo1fA/OjlZBj6GK3ak
X-Complaints-To abuse@iinet.com
X-DMCA-Complaints-To abuse@iinet.com
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2790
Xref csiph.com comp.lang.java.programmer:26227

Show key headers only | View raw


On 2/12/11 1:55 PM, Vasu wrote:
> Hi There! If somebody can help me solving following problem:
>
> We have 3 objects (rectOne, rectTwo and rect3) of rectangle class
> which also refers to point class for starting position of rectangle.
> Now, we have defined starting position of rectangles as 23, 94, now we
> change the starting position for rectTwo rectangle to 40 and 72, but
> we find that starting position of rectOne and rect3 also change
> whereas THAT WAS NOT INTENDED, so how do I achieve it ?  [...]

Among other things, stop using the same Point object to describe the 
origin for all three of your Rectangle instances.

Frankly, I can't imagine what would motivate someone to define their own 
custom Point and Rectangle structures anyway. What's wrong with the ones 
already in the JDK?

But if you're going to define your own, and you're going to use public 
instance fields (YUCK!) that reference mutable objects, then you need to 
make sure the code you write that uses your data structures does so in 
the right way, by either not sharing the same mutable object among more 
than one Rectangle, or by not mutating a mutable object that is shared.

I don't like the public fields in the JDK types, but at least they are 
always value types, and thus not sharable with other instances of the 
types.  Your problem would never have even come up if you'd just stuck 
with the JDK types.

Pete

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Object's properties changed Vasu <vasudevmukherjee@yahoo.co.uk> - 2011-02-11 21:55 -0800
  Re: Object's properties changed Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-12 15:01 +0800

csiph-web