raylopez99 said:
Analogy, not exact definition.
Except that we are using the term as it is exactly, precisely defined in
the context of .NET.
If you are going to misuse terms that have specific definitions, you
need to at least be clear that you are doing so intentionally.
[...]
No, you're not. "new" creates a new instance of an object. Cloning an
object requires the use of "new", but "new" very much does not imply
cloning.
Not what I said--"and other lines of code" meaning you are essentially
replicating ICloneable, such as if you were to make a copy constructor
in C# (which is possible with version 2.0, since earlier this year I
did just that).
You may have had some other intent specifically in mind. However,
you're not communicating your intent very well. I've never seen any
useful code that just calls "new" and doesn't have any other lines of
code. So your phrase "everytime [sic] you use 'new', and other lines of
code" is redundant and doesn't in any way distinguish from the basic use
of "new".
In any case, as I've already pointed out, in most cases only the class
itself is able to make a true clone of itself. You can't just call
"new" and then do some other stuff to create a clone from outside the class.
That's why ICloneable exists.
Beyond that, if what you meant to write was "every time you use 'new'
and exactly duplicate the data in an instance of a class, essentially
you are cloning", well...I have to agree with that, but don't find it a
useful statement since it's so obviously true. You might as well write
"every time you clone a data structure, essentially you are cloning".
[...]
The advantage to ICloneable is that the object provides a defined
interface to clone itself. In many cases, this would be the _only_ way
to clone an object, as the user of the object has no direct access to
private members that also have to be cloned as part of the cloning process.
Thanks for that information. "In many cases", meaning in some cases I
am correct. So I should drop the word "only" in "only advantage" and
should have said "an advantage".
IMHO, it is more that the use of the word "only" implies that the
advantage you're talking about is somehow trivial or unnecessary. The
"advantage" of which you write _is_ in fact the primary advantage of
ICloneable, but it's not so much an "advantage" as it is a critical
requirement for allowing a class to be cloned in a general-purpose way.
"Advantage" implies that there's some other way to do it, but which
might not be as good by some measure. But in this case, there's really
not any other way to do what ICloneable provides.
Yes, you could do it via a copy constructor, but doing by interface
allows for a consistent way for code to refer to an object as "something
that can be cloned" without having to know anything else about it (like
its type, required for calling a constructor). And you certainly cannot
in general clone an instance of a class from outside the class itself.
Usually, but a lot of people don't use ICloneable and simply "do it by
hand", the long way. That was my point.
Who are these "lot of people" of which you speak? How many situations
have you seen in which people clone objects by hand? How, in fact, are
these people able to do that, when the class encapsulates critical
information data not available to the code creating the clone?
But the behavior requested in the original thread is nearly trivial.
You may consider it trivial. However, it's a very specific kind of
behavior, commonly used in a variety of situations. And, most
importantly here, it is mutually exclusive with the topic of cloning.
Well, that statement, "O = O", is not only trivial, it's pointless and
has nothing to do with the original post or anything else in this
thread. No code here has been posted where a variable was assigned to
itself.
Much better to show that by judicious placing of
ICloneable you can make another copy of a reference or tracking
pointer,
First of all, making a copy of a reference is easy. You just copy the
reference. But that has nothing to do with cloning, so I'll assume what
you really meant to write was "you can make another copy of an instance
referred to by a reference". That out of the way...
That's not "better" at all. It's an entirely different technique, and
cannot in any way be implemented through cloning. As I have tried to
explain repeatedly, by cloning an object you completely block the
ability to do what was requested in the original post.
which is much more useful IMO in a real program--since it can
be a "snapshot" of a mutable class, a placeholder, something returned
by a method (such as a tracking pointer factory method), etc.
I have no idea why you think a technique that prevents the behavior
specifically being asked for is "much more useful". Cloning certainly
has its place, but in this context is entirely inappropriate.
Sorry if I confused you Pete,
You have not confused me. You are making the thread confusing for
others who may try to read it and understand how to implement the
behavior requested by the original poster.
but frankly I've been coding in C# for
just a few weeks now, and I'm beginning to see that I know as much or
more than some of the "veterans" in this NG!
Only been coding in C# for a few weeks? So when you wrote that "earlier
this year I did just that" (in reference to making a copy constructor),
you really meant "earlier this month"?
Frankly, it is pretty obvious from your posts that you know a lot less
about C# and programming in general that you think you do. It is true
that you frequently refuse to accept that you have made errors; in that
sense, it's clear you aren't receptive to the feedback you need in order
to have a correct understanding of the situation.
But make no mistake: that doesn't mean your feelings of superiority are
justified. All it means that you don't have the ability to do any
self-reflection in which you might discover mistakes you have made.
Basically, when you're wrong you just have no capability to understand
that you're wrong, so the fact that you're wrong continues to be a
mystery to you.
It's not that you're wrong all the time. But you are wrong a lot more
than you are willing to admit. This gives you an overinflated sense of
competence.
Pete