What's the better approach: using derived class in the service contracts (interface)? Or using the less specific class (the base class)? Suppose I have the base classes RequestDto
and ResponseDto
, all other classes inherit from one of them.
Is it a good practice to have all my methods receive or return this object, then I make the correct cast, like this :
ResponseDto GetInfos(RequestDto resquestDto)
ResponseDto GetInfosById(RequestDto resquestDto) {
return (ResponseDto)myResponseObject;
}
And then I cast the ResponseDto
to the correct derived class that I expect when I call these methods.
Thanks for your help.