共享单车技术架构_共享架构,而不是类型-解释吗?

共享单车技术架构

共享单车技术架构

Steve Maine posted in my comments section in response to a fellow who asked “What do you [folks, Doug Purdy, Don Box] mean by 'Share Schema, not Type'?

史蒂夫·缅因(Steve Maine)在我的评论部分中发帖回应了一个同胞的问题,他问“您[人们,道格·普迪(Doug Purdy),唐·沃克斯(Don Box)”是指共享模式,而不是类型

Here's my answer:

这是我的答案:

Types are immutable and unique. Like, Scott.Hanselman.Corillian.Whatever.  That's a unique type, especially when you add the concept of public keys.  If you wanted to use it, I'd need to give you the Assembly.
If we share "schema" then you could consume some XML that you and I agreed
upon - like a contract.  Then you can have Phil.Whatever.Yahoo.SomeOtherType that can consume the SAME XML (the contract) and think about it some other way.  The Schema is shared, not the type.

类型是不变的且唯一的。 就像Scott,Hanselman,Corillian一样。 这是一种独特的类型,尤其是当您添加公共密钥的概念时。 如果您想使用它,我需要给您大会。 如果我们共享“模式”,那么您可以使用您和我同意的一些XML 根据-像合同。 然后,您可以拥有Phil.Whatever.Yahoo.SomeOtherType,它可以使用SAME XML(合同)并以其他方式进行考虑。 架构是共享的,而不是类型。

Here's Steve's answer:

这是史蒂夫的答案

Good question. Certainly, XSD and the CTS (the .NET type system) are both things that you can use to define "types", and there's quite a lot of work that goes into marshalling data between those two different worlds. To get at the difference between schema and type, it's easiest to look at where we came from back in the olden days of COM.

好问题。 当然,XSD和CTS(.NET类型系统)都是您可以用来定义“类型”的东西,并且有很多工作要在这两个不同的世界之间编组数据。 要了解模式和类型之间的区别,最简单的方法就是回顾一下COM的历史。

In COM, two components communicated by sharing interface definition. COM interfaces defined a strict binary layout in memory. COM interfaces were uniquely identified by IID's and commonly defined in shared metadata via type libraries. The end result of this was that I could walk up to you and say "Here is an IFoo, its IID is XXX and it's defined in this .tlb file" and you would know *exactly* what the vtable layout of that interface would look like in memory.

在COM中,两个组件通过共享接口定义进行通信。 COM接口在内存中定义了严格的二进制布局。 COM接口由IID唯一标识,并且通常通过类型库在共享元数据中定义。 这样做的最终结果是,我可以走到你面前说:“这里是IFoo,其IID是XXX,并且在此.tlb文件中定义”。 并且您会*确切地*知道该接口在内存中的外观如何。

Because they were based around this idea of a binary specification of vtable layout, COM interfaces could only define methods. That is, they presented a set of behaviors to a consumer. Some of those behaviors might be to manipulate an object's local state via methods like GetXXXValue and SetXXXValue, but they were still behaviors nonetheless. Thus, when I walk up to you with a COM interface, I'm essentially telling you "here's the set of things that I can do".

因为它们基于vtable布局的二进制规范的思想,所以COM接口只能定义方法。 也就是说,他们向消费者展示了一组行为。 其中一些行为可能是通过诸如GetXXXValue和SetXXXValue之类的方法来操纵对象的本地状态,但是它们仍然是行为。 因此,当我使用COM接口走近您时,我实际上是在告诉您“这是我可以做的事情”。

This lead to all sorts of problems. It was very difficult to ensure semantic consistency across interface implementations because there was no way to contractually specify what an interface method was actually supposed to do -- COM interfaces told you how to call methods, but they didn't tell you what effect calling those methods will have. Another problem with COM interfaces was that they were immutable once published. If you wanted to add a member to a published interface, you had to create a whole new interface. That's why we get things like IDispatch2Ex -- COM interfaces just didn't grow very nicely.

这导致各种各样的问题。 确保接口实现之间的语义一致性非常困难,因为无法以合同方式指定接口方法实际上应执行的操作-COM接口告诉您如何调用方法,但它们并未告诉您调用那些方法的效果方法将有。 COM接口的另一个问题是,一旦发布,它们是不可变的。 如果要向已发布的界面添加成员,则必须创建一个全新的界面。 这就是为什么我们会得到IDispatch2Ex之类的原因-COM接口的增长并不十分理想。

Web services attempt to solve these problems by communicating in terms of schemas and contract. A schema is a description of the legitimate contents of a message. It communicates only state, and says nothing about behavior. For example, a person schema allows to mechanically verify assertions like "I am expecting a Person, and that Person will at least have FirstName and a LastName." There is nothing in the schema that says what that person can *do*, because it really can't do anything -- it's just a blob of structured stuff. Furthermore, if these schemas are designed to take advantage of XML's intrinsic support for open content, people can evolve these schemas transparently without breaking old systems.

Web服务试图通过根据模式和协定进行通信来解决这些问题。 模式是对消息合法内容的描述。 它只传达状态,不表达任何行为。 例如,人模式允许机械地验证诸如“我期待一个人,并且该人将至少具有名字和姓氏”之类的断言。 模式中没有任何内容说明该人可以*做*的事情,因为它实际上无能为力-只是一堆结构化的东西。 此外,如果将这些架构设计为利用XML对开放内容的内在支持,则人们可以透明地演化这些架构而不会破坏旧系统。

Contracts are the way that web services describe their behaviors. Contracts are used to define the legal patterns of messages that two services may exchange. For example, a contract for a purchase ordering system might be a mechanically verifiable expression of the idea that "if you send me a Purchase Order message(defined by the PurchaseOrder schema) and I can successfully process it, I'll send you back a Purchase Order Filled message (defined in the PurchaseOrderFilled schema). By contractually specifying the legal sets of inputs and outputs to a system, web services help ensure consistent semantics across services (which is something that COM could never do).

合同是Web服务描述其行为的方式。 合同用于定义两个服务可以交换的消息的合法模式。 例如,采购订购系统的合同可能是该想法的机械可验证的表达,即“如果您向我发送采购订单消息(由PurchaseOrder模式定义),并且我可以成功处理它,我会回发给您采购订单已满消息(在PurchaseOrderFilled模式中定义)。 通过以合同方式指定系统的合法输入和输出集,Web服务有助于确保服务之间语义的一致性(这是COM永远无法做到的)。

In summary, a type is a closed encapsulation of state+behavior. A schema is a potentially open description of state, while a contract is a description of the messaging patterns that define service behaviors.

总而言之,类型是状态+行为的封闭封装。 模式是状态的潜在开放描述,而合同是定义服务行为的消息传递模式的描述。

翻译自: https://www.hanselman.com/blog/share-schema-not-type-explained

共享单车技术架构

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值