是否可以进行DDD和REST接口以及语言映射? [英] Is it possible to do DDD and REST interface and language mapping?

查看:84
本文介绍了是否可以进行DDD和REST接口以及语言映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

REST具有统一的接口约束,以下是非常压缩的基于意见的格式。




  • 您必须使用HTTP,URI,MIME等标准...

  • 您必须使用超链接。

  • 您必须使用RDF vocabs来对数据和具有语义的超链接进行注释。

  • 您需要执行所有这些操作以使客户端分离据我了解,



具有CQRS(或不具有CQRS)的DDD非常相似。




  • 通过CQRS,您可以定义一个与域模型进行交互的接口。该界面由查询类的命令组成。

  • 通过DDD,您可以定义域事件以将域模型与持久性详细信息分离。

  • ,通过DDD每个有界上下文中都有一种表示语义的无处不在的语言。

  • 您需要执行所有这些操作,以使领域模型与外界完全脱钩。



是否可以将REST统一接口映射到由命令,查询和域事件定义的域接口? (因此REST服务代码将自动生成。)



是否可以将链接的数据语义映射到无所不在的语言? (因此,您不需要定义非常相似的术语,只需查找并重复使用现有的词汇。)



请在回答中添加一个非常简单的映射示例,为什么选择是或

解决方案

我认为这是不可能的。我相信有一个术语描述了这个问题,它叫做本体对齐



在这种情况下,至少具有3种本体:




  • 以下语言的普遍存在的语言(UL):域模型

  • REST服务的特定应用程序词汇(ASO)

  • 特定应用程序词汇使用的链接的开放数据词汇(LODO)



所以我们至少有2种对齐方式:




  • UL:ASO对齐

  • ASO:LODO对齐



我们的问题是与UL:ASO对齐有关,所以让我们谈谈这些本体。



UL是面向对象的,因为我们正在谈论DDD和域模型。因此,大多数域对象实体值对象是真实对象,而不是数据结构。其中的非面向对象部分是DTO,例如 command + domainEvent query + result 和<$ c域模型的界面上出现$ c>错误。



相反,ASO严格是程序性的,我们使用一套标准方法(过程)来操纵资源(数据结构)。



所以从我的角度来说,我们谈论的是两种截然不同的事情,我们有以下选择:




  • make ASO更多面向对象-> RPC

  • 使UL少面向对象->贫血域模型



所以从我的角度来看,我们可以做以下事情:




  • 我们可以自动将实体映射到资源,将命令映射到操作CRUD,例如 HydraBundle 使用活动记录来完成此操作(我们可以在使用DDD且没有CQRS的情况下执行相同的操作)

  • 我们可以通过复杂的域模型手动将命令映射到操作




    • 操作 POST事务{...} ca n结果为 SendMoneyCommand {...}

    • 操作获取订单/ 123 /总计可以生成 OrderTotalQuery {...}


  • 我们无法通过复杂的域模型将实体映射到资源,因为我们必须定义新资源来描述新服务或新实体方法,例如




    • 操作 POST交易{...} 可能会导致 account.sendMoney(anotherAccount,...)

    • 操作 GET order / 123 / total 可以在读取的数据库上导致SQL查询,而无需触及任何一个实体




我认为不可能在两者之间进行这种本体对齐DDD + CQRS和REST,但我不是该主题的专家。我认为我们可以做的是使用资源类,属性和操作创建特定于应用程序的词汇,并将操作映射到命令/查询,并将属性映射到命令/查询属性。


REST has a uniform interface constraint which is the following in a very zipped opinion based format.

  • You have to use standards like HTTP, URI, MIME, etc...
  • You have to use hyperlinks.
  • You have to use RDF vocabs to annotate data and hyperlinks with semantics.
  • You do all of these to decouple the client from the implementation details of the service.

DDD with CQRS (or without it) is very similar as far as I understand.

  • By CQRS you define an interface to interact with the domain model. This interface consists of commands an queries classes.
  • By DDD you define domain events to decouple the domain model from the persistence details.
  • By DDD you have one ubiquitous language per bounded context which expresses the semantics.
  • You do all of these to completely decouple the domain model from the outside world.

Is it possible to map the REST uniform interface to the domain interface defined by commands and queries and domain events? (So the REST service code would be generated automatically.)

Is it possible to map the linked data semantics to the ubiquitous languages? (So you wouldn't need to define very similar terms, just find and reuse existing vocabs.)

Please add a very simple mapping example to your answer, why yes or why not!

解决方案

I don't think this is possible. There is a term which I believe describes this problem, it is called ontology alignment.

In this case have have at least 3 ontologies:

  • the ubiquitous language (UL) of the domain model
  • the application specific vocab (ASO) of the REST service
  • the linked open data vocabs (LODO) which the application specific vocab uses

So we have at least 2 alignments:

  • the UL : ASO alignment
  • the ASO : LODO alignment

Our problem is related to the UL : ASO alignment, so let's talk about these ontologies.

The UL is object oriented, because we are talking about DDD and domain model. So most of the domain objects entities, value objects are real objects and not data structures. The non-object-oriented part of it are the DTOs like command+domainEvent, query+result and error on the interface of the domain model.

In contrast the ASO is strictly procedural, we manipulate the resources (data structures) using a set of standard methods (procedures) on them.

So from my aspect we are talking about 2 very different things and we got the following options:

  • make the ASO more object oriented -> RPC
  • make the UL less object oriented -> anaemic domain model

So from my point of view we can do the following things:

  • we can automatically map entities to resources and commands to operations by CRUD, for example the HydraBundle does this with active records (we can do just the same with DDD and without CQRS)
  • we can manually map commands to operations by a complex domain model

    • the operation POST transaction {...} can result a SendMoneyCommand{...}
    • the operation GET orders/123/total can result a OrderTotalQuery{...}
  • we cannot map entities to resources by a complex domain model, because we have to define new resources to describe a new service or a new entity method, for example

    • the operation POST transaction {...} can result account.sendMoney(anotherAccount, ...)
    • the operation GET orders/123/total can result in an SQL query on a read database without ever touching a single entity

I think it is not possible to do this kind of ontology alignment between DDD+CQRS and REST, but I am not an expert of this topic. What I think we can do is creating an application specific vocab with resource classes, properties and operations and map the operations to the commands/queries and the properties to the command/query properties.

这篇关于是否可以进行DDD和REST接口以及语言映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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