I recently asked this question: Expose XML or Objects - thanks all for the responses.
One point to clarify.
- The API will always be accessed remotely (i.e. as a service), most probably via webservices or WCF.
I agree that in theory a strongly typed API exposing objects as the inputs/outputs is the right way to go. However, I feel that there is still an argument to be made for exposing XML. As I see it the reasons for using XML are:
- The business rules can be written by business analysts in Schematron.
- The interface is weakly typed, but as soon as it is called the data can be validated against data and business rules.
- The service's implementation will be simpler. There won't be any need to create an domain object model.
- The XML schema is already defined (we have a data dictionary of schema).
Using web services technology means that an XML based API will not need to change as new car 'types' are added, e.g.
void AddNewCar( string newCarXml ) string[] GetCars( /* some query conditions */ )
If we used an object based API then adding a new type would require a new query method defining the possible derived types that could be returned (see extending web services). Updating the web service like this would require this services and all existing clients to be rebuilt and redeployed.
What does an object based API give us? A strongly typed declarative interface. It does not provide any more abstraction than XML (XML is itself an abstraction). What does the object based API cost? It costs an entire set of domain objects which will need business rules and data validation.
So, what is my question? Give me an un-defeatble, unarguable reason why I should go with objects.