I have two two types of base class;
public abstract class Base
{
public abstract object Work();
}
public abstract class AuthenticatedBase : Base
{
public abstract object Work(T request);
}
The authenticated class does some extra work to check a login beforehand. Then I have different classes extending from both base classes;
public class A : Base
{
public override object Work()
{
// Work here
}
}
public class B : AuthenticatedBase
{
public override object Work(T request)
{
// Work here
}
}
Basically, when I create a new class B that derives from AuthenticatedBase, Visual Studio says I need to implement Work() from the Base class even though I have an alternate implementation in AuthenticatedBase that I am overriding, admittedly with different parameters. What should I be doing so that I don’t have to implement the Work() method from the base class in inherited classes?
You have to implement it, there is no way around it. This is the case where multiple inheritance would come in handy.
You could use composition so that
Bhas a reference to anA. ThenB.Work()can callA.Work().Alternatively, implement
B.Work()so that it callsB.Work(T). Or even haveBase.Work()be a virtual method with the base implementation fromA.