I have the following class
public class classB : classA
which contains function dostuff
Now I have a class SUPER, which has an instance of B amongst its variables
classB SUPER_B;
and that has a ‘redefinition’ of ‘dostuff’ amongst its methods.
Basically, what I need is that when classB calls ‘dostuff’, it does not call its internal dostuff, but SUPER’s dostuff implementation instead.
Substantially, I would need that, on SUPER’s initialization, classB’s ‘dostuff’ be replaced with SUPER’s dostuff.
It’d sort of make sense if there was a way to retrieve B’s ‘dostuff”s reference, but I don’t know how to achieve that.
I’ve looked into virtual and Func, but they seem to require that SUPER be a derivate of B
You cannot force a method change upon a class from the outside. There are ways to achieve functionality like that when either (1) classB is designed in such a way as to support replacing its methods, e.g. though a settable delegate, or (2) if classB implements an interface, which you can implement, wrap classB inside it, and replace a method.
Example #1 – settable delegate:
Example #2 – interfaces.