Method call immediate relative class

Is it possible to call the base of the base method? I.E. not a "direct" ancestor of a derived class?

public class a { public virtual void test() { } } public class b : a { public override void test() { //... base.test(); } } public class c : b { public override void test() { //... //possible to call test() in class a, without calling it in class b? //((a)base).test(); //doesnt work } } 
+4
source share
2 answers

No, this is impossible and goes against the principles of OOP. If you need to do this, you have probably improperly designed your system.

+4
source

Not with C #. C # allows you to call methods only for the base class.

The CLR, on the other hand, allows this. You can do this with reflection, or by directly writing IL. I assume C ++ / CLI also supports this.

But I would review the design. Skipping redefinition of poorly designed odors and interrupting the encapsulation of your base class.

+3
source

Source: https://habr.com/ru/post/1434576/


All Articles