Is it possible to call the current classes methods in a class inheritance?
Lets say we have a class A and a Class B which inherits from A. Now both have an “initialize” method, meaning it gets overriden in B. Now i can not use “base.initialize” to call A’s “initialize” from there. Instead im trying to call it from the lower classes constructor (so A’s constructor), which gets called for all inherited classes.
So now i want to call A’s “initialize” on A’s constructor. But when i try that, the overriding constructor of B gets called.
So is there something to tell VS (or c#) that i’m explicitly calling the methods of the class im currently in (this.method() didn’t work)?
If you mark a method
Initializeas virtual, that means that a derived class is free to override that method, potentially not callingbase.Initializein the process. If it is not okay if that scenario occurs, then don’t mark the method as virtual.In your case, it sounds like you just need two private
Initializemethods in each class:Alternatively, you might want to have a look at the Template Method design pattern. You could design your classes like this: