Serialization is an
alternative way for deep copy.
In Serialization, whole
object graph into a persistent store and read whole object graph back when
needed. This is exactly what you want when you deep copy an object.
Note, when you deep
copy through serialization, you should make sure that all classes in the
object's graph are serializable.
Advantages
When you implement the deep cloning, the copied object may contain some other object its references are copied recursively in deep copy.
Cyclic dependencies will be a big problem while implementing deep copy. It does implements deep copy implicitly and gracefully handling cyclic dependencies.
Disadvantages
Serialization is more expensive than using object.clone().
Not all objects are serializable (transient variable cannot be cloned).
No comments:
Post a Comment