directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: Avoiding use of clone()
Date Sat, 27 Oct 2007 20:38:14 GMT

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


Mime
View raw message