In this video we will discuss
1. Significance of Copying
2. MemberwiseClone Method and ICloneable Interface
3. Prototype Design Pattern Example
Significance of Copying
1. The idea of using copy is to create a new object of the same type without knowing the exact type of the object we are invoking
2. Shallow Copy and Deep copy plays prominent role in copying the objects in Prototype Design Pattern
3. Creating the required object once and by creating the subsequent required objects by cloning helps reducing the time for creating the objects
4. With Prototype design pattern, based on the requirement situations we can save memory by cloning the objects
Example : Adapting to clone an object which consists of many strings (immutable) is a good idea than creating an object
MemberwiseClone and ICloneable Interface
MemberwiseClone Method :
1. The MemberwiseClone method is part of system.object and creates a shallow copy of the given object.
2. MemberwiseClone Method copies the nonstatic fields of the chosen object to the new object.
3. In the process of copying, if a field is a value type, a bit by bit copy of the field is performed. If a field is reference type, the reference is copied but the referenced object is not.
ICloneable Interface :
1. The ICloneable interface provides with a customized implementation that creates copy of an existing object.
2. The ICloneable interface contains one member, the clone method, which is intended to provide support beyond MemberwiseClone method.
Text version of the video
Design Patterns Tutorial playlist
Design Patterns Text articles and slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic