On 5/13/05, Vince Bonfanti <[EMAIL PROTECTED]> wrote:
> I'm not sure I understand what you mean by this. By "state" you mean the
> object attributes (instance variables). Wouldn't cloning an object merely
> copy the current state? Isn't this how Object.clone() works in Java--thus
> inherently supporting a way to "generically 'clone' an object in (a)
> meaningful way"?

But that's a default behavior that any vaguely complex class needs to
override. Most objects of any complexity have two types of state - one
you can (and should) clone and one that needs to be reset or
recalculated as part of a cloning operation. I know there's a few
whitepapers out there that cover this issue but I'm coming up blank
right now.

Consider composition. A car has-a engine. So you create an engine
object and you create a car object and store a reference to the engine
inside the car. Now you clone the car. The clone has to copy all of
the car's state and *clone* the engine - otherwise two cars will share
the same physical engine object! Now consider that your car has a
reference to a manufacturer object. You don't want to clone that when
you copy the car, you just want to copy the reference - the
manufacturer is a singleton and all Mercedes should refer to the same
Mercedes manufacturer object. Even if you just say that clone() should
copy simple data and call clone() on complex data, you then have
engine.clone() that returns a copy of itself but manufacturer.clone()
returns itself, not a copy.

Does that example help?
-- 
Sean A Corfield -- http://corfield.org/
Team Fusebox -- http://fusebox.org/
Got Gmail? -- I have 50, yes 50, invites to give away!

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to