I have four classes. Request, DerivedRequest, Handler, DerivedHandler. The Handler class has a property with the following declaration:
public abstract Request request { get; set; }
The DerivedHandler needs to override this property so that it returns DerivedRequest instead:
public override DerivedRequest request { get; set; }
Does anyone have any ideas about how to make this work?
This isn’t really a good way to structure things. Do one of the following
1) Just don’t change the return type, and override it normally in the subclass. In
DerivedHandleryou can return an instance ofDerivedRequestusing the base class signature ofRequest. Any client code using this can choose to cast it toDerivedRequestif they want to.2) Use generics instead if they are not supposed to be polymorphic.