How to override an overridden method which calls the base method

Viewed 66

I have a method Hello in class A, which should be overridden by class B. Therefore the overridden method in B has to call the base method to prepare something.

The method DoSomeThing is the additional functionality of this method. Now I want to override B.Hello in the new class C in order to change logic of B.DoSomeThing.

Requirements:

  • C.Hello needs the method call of A.Hello, too, in order to do some basic preparations
  • Only B.DoSomeThing should be replaced width new functionality, defined in C.DoSomeThing2
  • I am not allowed to change code inside A and B
public class A 
{
   protected virtual void Hello() {}
}

public class B : A 
{
   protected override void Hello() {
      base.Hello();

      DoSomeThing();
   }
}

public class C : B 
{
   protected override void Hello() {
      ???????????????

      DoSomeThing2();
   }
}

I cannot call the base method of class A. What would be the best solution for my problem?

Simply copy and paste the code of A.Hello wouldn't work because of private methods in A.

EDIT: class C has to inherit from class B.

0 Answers
Related