I have a domain object that is used throughout my application. I'm writing a web service to allow programmers to enter these types of objects programmatically. Should I accept my domain object as a param开发者_如何学编程eter, or should I write a specific object for use exclusively in web services?
I prefer to write a specific object for use exclusively in web services, for multiple reasons:
- Less coupling between domain objects and web service. If my domain object changes in a way that doesn't affect web service consumers, I still have to rebuild the web service.
- I can control what properties should or should not be available to web service consumers.
- There may not be a one-to-one mapping between my domain object and how I want the object to be treated in the web service. For instance, I may want to split the properties of the domain object into three separate web service methods, dealing with different sets of properties.
In short, using another object layer for the web service is more flexible, de-coupled, and controlled.
精彩评论