|
Home > Archive > Apache Directory Project > October 2007 > Avoiding use of clone()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Avoiding use of clone()
|
|
| Alex Karasulu 2007-10-27, 7:11 pm |
| Hi Emmanuel, and others,
I was taking another look at these ServerEntry interfaces etc and noticed
that you define
the clone() method as supported within the interfaces themselves.
I may be wrong but I've always tried to avoid defining the clone() method in
interfaces and
have gone to great lengths to avoid using the clone() method. I prefer to
use factories or
constructors instead. For me the clone operation is scary and leads to a
lot of confusion.
Most of the time unless I have to support it because of a class I'm
extending I will deal with
it but when I can I try to avoid it.
Emmanuel was wondering if you see supporting clone() as critical and
recommend we keep
it?
I know just having a feeling is not enough to say using clone is dangerous
but I've always ran
into issues with it and the variance in the semantics to the point where
dealing with it was not
worth the trouble.
Please could anyone with a clearer understanding of the pros and cons
provide some further
guidance on this topic?
Thanks,
Alex
| |
| David Jencks 2007-10-27, 7:11 pm |
|
On Oct 27, 2007, at 11:56 AM, Alex Karasulu wrote:
> Hi Emmanuel, and others,
>
> I was taking another look at these ServerEntry interfaces etc and
> noticed that you define
> the clone() method as supported within the interfaces themselves.
>
> I may be wrong but I've always tried to avoid defining the clone()
> method in interfaces and
> have gone to great lengths to avoid using the clone() method. I
> prefer to use factories or
> constructors instead. For me the clone operation is scary and
> leads to a lot of confusion.
> Most of the time unless I have to support it because of a class I'm
> extending I will deal with
> it but when I can I try to avoid it.
>
> Emmanuel was wondering if you see supporting clone() as critical
> and recommend we keep
> it?
>
> I know just having a feeling is not enough to say using clone is
> dangerous but I've always ran
> into issues with it and the variance in the semantics to the point
> where dealing with it was not
> worth the trouble.
>
> Please could anyone with a clearer understanding of the pros and
> cons provide some further
> guidance on this topic?
>
I doubt I have a clearer understanding but Joshua Bloch's Effective
Java has 8 pages pointing out how hard it is to write clone methods
correctly and the problems they cause and how copy constructors or
factory methods have much clearer semantics and implementations. I
never feel like I know what is going to happen when I call clone :-)
thanks
david jencks
> Thanks,
> Alex
|
|
|
|
|