Do I need a method that creates an empty clone of an object in a base class? For example:
public class ChildClass : ParentClass { public ChildClass() { } } public class ParentClass { public SomeMethod() {
So far, we have an abstract method defined in the parent class. And all child classes implement them. But the implementation is the same for everyone, just for a different type.
public class ChildClass : ParentClass { public ChildClass() { } public ParentClass CreateEmpty() { return new ChildClass(); } } public class ParentClass { public SomeMethod() {
Is there a way to do this from the parent class so that I don't have to execute the same logic for every other child class? Note that there may be more levels of inheritance (e.g. ChildChildClass: ChildClass: ParentClass).
bsh152s
source share