API设计:公开XML或对象#2 [英] API Design: Expose XML or Objects #2

查看:143
本文介绍了API设计:公开XML或对象#2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我问这个问题:的揭露XML或对象 - 感谢所有的答复。

I recently asked this question: Expose XML or Objects - thanks all for the responses.

有一点澄清。


  • 的API将始终远程(即服务),最有可能通过web服务或WCF访问。

我同意,在理论上一个强类型的API揭露对象的输入/输出是的右键的路要走。不过,我觉得还是有用于公开XML进行争论。当我看到它使用XML的原因是:

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:


  1. 业务规则可以由业务分析中的Schematron编写的。

  2. 的接口弱类型的,但只要它被称为数据可以针对数据和业务规则进行验证。

  3. 服务的实现会更简单。不会有任何需要创建一个域对象模型。

  4. XML架构已定义(我们有架构的数据字典)。

  5. 使用Web服务技术是指一种基于XML API不需要改变,因为新车的类型被加入,例如

  1. The business rules can be written by business analysts in Schematron.
  2. The interface is weakly typed, but as soon as it is called the data can be validated against data and business rules.
  3. The service's implementation will be simpler. There won't be any need to create an domain object model.
  4. The XML schema is already defined (we have a data dictionary of schema).
  5. 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 */ )

如果我们使用基于对象的API,然后添加一个新的类型,需要定义一个可以返回的可能派生类型的新查询方法(请参阅扩展Web服务)。更新这样的Web服务需要此服务的所有的重新构建和重新部署现有客户。

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.

什么是基于对象的API给我们?强类型声明的接口。它不提供任何比XML更抽象(XML是本身的抽象)。什么对象基于API的成本?它的成本一整套这将需要业务规则和数据验证域对象的。

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.

那么,什么是我的问题吗?给我一个未defeatble,无可争辩的原因,我应该去的对象。

So, what is my question? Give me an un-defeatble, unarguable reason why I should go with objects.

推荐答案


  • 对象可以有更好的表现(这里想二进制序列化)。

  • 对象可以有更强的简单类型验证。

  • 对象让你把更接近数据结构定义的验证和业务规则。

  • 其性质对象允许您编写简单的业务规则和验证,因为大部分的嵌入在对象定义本身。

  • 对象也可以定义的行为。

  • 的.Net可以很方便地通过序列再次打开对象转换为XML和背部,使物品大部分相同的好处为XML。

这篇关于API设计:公开XML或对象#2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆