Second pattern out is the Prototype pattern. This is a simple creational pattern that you can use when you want to create an object that you later on wish to create many copies, clones, of. The clones will get the same properties as the prototype.
In my sample code on github I use the MemberwiseClone from the .NET framework. Take note that this creates a shallow copy of the object. Any references that the object holds will not be cloned, hence both the original and the clone will reference the same object.
If you do need a deep copy, there is information available on the MemberwiseClone page on different options to achieve this.
In my sample code on github I use the MemberwiseClone from the .NET framework. Take note that this creates a shallow copy of the object. Any references that the object holds will not be cloned, hence both the original and the clone will reference the same object.
If you do need a deep copy, there is information available on the MemberwiseClone page on different options to achieve this.
Kommentarer
Skicka en kommentar