Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[dsdp-tm-dev] RE: IHostFilePermissions#clone()

Hi Dave,
when you use the "duplicate()" approach, I think you should
mention somewhere in Javadoc that any extender who derives
from the HostFilePermissions implementation MUST also
override the duplicate() method, or it creates a wrong object:
A extends HostFilePermissions
A.duplicate() creates a HostFilePermissions object rather than an "A" object
That's why I'm personally in favor of the clone() approach:
  1.) clone() automatically copies instance variables
  2.) clone() ensures correct object type if you simply do this:
public Object clone() {
   return super.clone();
If you want this, but feel uneasy making the change, I can make it for you.
See Javadoc for
Martin Oberhuber, Senior Member of Technical Staff, Wind River
Target Management Project Lead, DSDP PMC Member

From: David McKnight [mailto:dmcknigh@xxxxxxxxxx]
Sent: Wednesday, January 23, 2008 2:14 PM
To: Oberhuber, Martin
Cc: Target Management developer discussions
Subject: Re: IHostFilePermissions#clone()

I've changed the code now to use duplicate().

David McKnight    
Phone:   905-413-3902 , T/L:  969-3902
Internet: dmcknigh@xxxxxxxxxx
Mail:       D1/YFY/8200/TOR

"Oberhuber, Martin" <Martin.Oberhuber@xxxxxxxxxxxxx>

23/01/2008 04:51 AM

David McKnight/Toronto/IBM@IBMCA
"Target Management developer discussions" <dsdp-tm-dev@xxxxxxxxxxx>

Hi Dave,

your new IHostFilePermissions#clone() method looks
odd to me, can you explain it?

Why don't you just require IHostFilePermissions
implementers to also implement Cloneable and
provide a public Object clone() method? See the
Java API docs for the Cloneable interface.

If you really don't like the Cloneable approach,
you'd better call your method differently
(e.g. duplicate()) and avoid the extra parameter.
Only like that you can ensure that if you have
two different implementations of IHostFilePermissions,
the method will create a proper duplicate.

Martin Oberhuber, Senior Member of Technical Staff, Wind River
Target Management Project Lead, DSDP PMC Member

Back to the top