S
smith
I've been making deep copy clones of objects since my second week or so with
..Net (it took me the first week to realize that shallow copies were usually
worthless as "clones").
Normally I call my method "Clone" ... it's just a naming habit I got into
with VB5/6 using LSET on UDTs for serializing state and creating copies of
objects.
The way I do it is of course with .Net is the wya most everyone does it,
mark the class with the Serializable attribute, implement ISserializable
with it's constructor and GetObjectData. The Clone method does the
traditional binaryformater and memory stream serialization and the method
returning an object of the same type as the running instance (though I often
overload the Clone method and use custom serialization to instead convert
the object to another type, such as a state-only object for tighter
remoting). No rule breaking here, ISerializable's "propertybagish" system
is logical.
But, here's the question: In my three years of primarily doing .Net, most of
my clones (found in nearly every one of my apps) never specifically
implemented ICloneable. I'll add it if I'm feelign picky but even when I do
add it, I always just look at that interface and scratch my head ... There
seems to be nothing worthwhile in using it, since I'm doing all of the
actual work myself, using the syntax (albeit out of pre-.Net habit) and
just don't need the "reminder" that I have a Clone method. Also, my Clones
output an actual type rather than an Object.
Forgive my ignorance, but can you tell me a real reason for specifically
typing out the "Implements ICloneable", beyond just "it's what you're
supposed to do"?
There's doing "the right thing" for a good reason and then there's going
overboard ... in this little thing I wonder the basic logic.
Thanks.
Robert Smith
Kirkland, WA
www.smithvoice.com
..Net (it took me the first week to realize that shallow copies were usually
worthless as "clones").
Normally I call my method "Clone" ... it's just a naming habit I got into
with VB5/6 using LSET on UDTs for serializing state and creating copies of
objects.
The way I do it is of course with .Net is the wya most everyone does it,
mark the class with the Serializable attribute, implement ISserializable
with it's constructor and GetObjectData. The Clone method does the
traditional binaryformater and memory stream serialization and the method
returning an object of the same type as the running instance (though I often
overload the Clone method and use custom serialization to instead convert
the object to another type, such as a state-only object for tighter
remoting). No rule breaking here, ISerializable's "propertybagish" system
is logical.
But, here's the question: In my three years of primarily doing .Net, most of
my clones (found in nearly every one of my apps) never specifically
implemented ICloneable. I'll add it if I'm feelign picky but even when I do
add it, I always just look at that interface and scratch my head ... There
seems to be nothing worthwhile in using it, since I'm doing all of the
actual work myself, using the syntax (albeit out of pre-.Net habit) and
just don't need the "reminder" that I have a Clone method. Also, my Clones
output an actual type rather than an Object.
Forgive my ignorance, but can you tell me a real reason for specifically
typing out the "Implements ICloneable", beyond just "it's what you're
supposed to do"?
There's doing "the right thing" for a good reason and then there's going
overboard ... in this little thing I wonder the basic logic.
Thanks.
Robert Smith
Kirkland, WA
www.smithvoice.com