This can be used to clone an object. We can create our own interface
IProtoType<T> and specify a method of
DeepCopy which will remove the ambiguity we got from trying ICloneable but its would still mean traversing the object tree manually so the copy is done recursively.
If you want to clone rather look at the suggestions under the creational Prototype Pattern.
Address which implement
IPrototype - the nice thing now with
IPrototype is the API would return the given type so no casting is needed.
public interface IPrototype<T>
The implementation would be
public class Person : IPrototype<Person>
var carl = new Person("Carl", new Address("Sale Street", 66));
Output would be:
FirstName: Carl, Address: StreetName: Sale Street, HouseNumber: 66
- [PrototypePattern/ICloneableDemo.cs](https://github.com/carlpaton/Boilerplate/blob/master/.Net Core Console Application/PatternsAndPrinciples/PrototypePattern/ICloneableDemo.cs)