Original Post
Why is there no ICloneable only ICloneable? Is there any way to specify the type so there is no need to box and unbox when I make a copy of the object?
class MyClass : ICloneable{ public MyClass Clone() { // do the clone stuff here return myClone; } object ICloneable.Clone() { return Clone(); }}Quote:You're correct. Boxing only applies to value types.
Original post by SpodiBtw, unless I'm horribly mistaken, boxing only applies to value types.
Quote:It's another method that a developer can use to define the behavior of his or her objects. Flexibility is key. Two things should be assumed: 1) If an object implements ICloneable then the original developer made a conscious decision and the interface is defined appropriately; 2) that if you choose to implement the interface you should perform a copy - deep or shallow, as appropriate - for all of your type's members.
Original post by Spodi
ICloneable, in my opinion, was just a poor idea from the start. Like VizOne said, its hard to define what exactly is a clone. Does it make a new deep copy of the object? If so, does it make a deep copy of objects it references? Just ones that also implement ICloneable? In the end, you can't be sure what anything is.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more