Say you have an abstract base class:
abstract class abstractBaseClass {
public abstractBaseClass(object argument);
public abstractBaseClass instanceMethod() {
//call the constructor of the concrete class here.
}
}
And you have a base class:
class baseClass {
public baseClass(object argument) : abstractBaseClass(object argument)
}
If you have an instance method on abstractBaseClass is there any way to call the constructor of that concrete class inside the instance method without resorting to reflection?
It seems to be reasonable to assume there is at least one constructor with the signature concreteBaseClass(object) on any given concrete base class.
You already do that, actually.
Abstractclass can not be initialized if not by it’s derivates.The real object type here is
baseClass, so thectorof it will be called by convention.EDIT
if you mean construct *a new * real object that is hosted inside abstract reference (something that is mantioned by Sevy in comments), I would suggest, at this point, just use
override pattern. Something like this:
after use it like
Something like this, just an idea.
You should figure out by yourself the real, concrete implementation that fits your needs.