0

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.

dda
  • 6,030
  • 2
  • 25
  • 34
riadh gomri
  • 869
  • 1
  • 15
  • 21

1 Answers1

0

You can look here: http://channel9.msdn.com/Blogs/Subscribe/DataContract-Coupling-in-Messaging. This podcasts is about data coupling between the service and service consumers. It comes to conclusion that using polymorphic types in service interface is a bad thing because it introduces a very tight coupling between the service and its consumer. Hope it helps.