实施领域驱动设计的有效方式有效、领域、方式

2023-09-04 22:44:56 作者:遇我者疯

我已经有很多的经验,使用C#编写领域驱动的应用程序。在更多的应用程序我写我越发现,我想利用不适合那么好与标准的C#/面向对象技术的方法:

I've had a lot of experience with writing domain driven applications using C#. The more applications I write the more I find that I want to take an approach that doesn't fit that well with standard C#/OO techniques:

在我想要的,因为他们是很容易的测试编写尽可能多的纯函数越好。 在我想写我的业务逻辑更声明的方式。

所以,我一直在寻找功能性语言,如F#。毕竟没有理由为什么领域驱动设计的的的使用面向对象来实现。

So I've been looking at functional languages such as F#. After all there is no reason why domain driven design has to be implemented using OO.

我想知道如果任何人有任何想法/经验做领域驱动设计设计,同时使用功能性的语言。特别是:

I was wondering if anyone has any ideas/experience with doing Domain driven design design whilst using a functional language. Especially:

什么功能领域模型是什么样子? 你将如何从抽象的领域模型的数据访问层。

推荐答案

免责声明:我只有约领域驱动设计一个模糊的认识,所以答案可能不使用正确的术语和可能过于集中于code而不是笼统的概念,但这里有一些想法反正... 的

Disclaimer: I have only a vague knowledge about domain driven design, so the answer may not use the right terms and may be overly focused on code rather than general concepts, but here are some thoughts anyway...

重点放在理解的域的,而不是设计的特定功能或对象在他们看来很自然的人们如何使用函数式编程语言一般。很多时候(至少在功能应用程序的一部分),你开始通过设计来描述数据结构(或模式),你的工作与世界接轨。该数据结构从实现分离,所以它很好的模型的域

The focus on understanding the domain rather than designing specific features or objects to implement them seems very natural to how people use functional programming languages in general. Very often (at least in a part of a functional application) you start by designing data structure that describes (or models) the world you're working with. The data structure is separated from the implementation, so it nicely models the domain.

一个非常好的例子是在paper关于撰写金融合约的。这个例子是金融合同的估值(和其他处理)的应用程序。最重要的是要建立契约模型 - 它们是什么实际?要回答这个问题,作者设计了一个数据结构描述的合同。是这样的:

A very nice example is described in paper about composing financial contracts. The example is an application for valuation (and other processing) of financial contracts. The most important thing is to create model of the contracts - what are they actually? To answer that, the authors design a data structure for describing contracts. Something like:

type Contract = 
  | Zero                         // No trades
  | Single of string * float     // Single trade (buy something for some price)
  | And of Contract * Contract   // Combine two contracts 
  | Until of Contract * DateTime // Contract that can be executed only until...
  // (...)

有一些其他情况,但数据结构非常简单和模式的广泛被金融业所用pretty的复杂的合同。

There are a few other cases, but the data structure is very simple and models a wide range of pretty complex contracts that are used in the financial industry.

摘要我觉得重点是用于在世界模型(和使用它们的实现是分开的)数据结构非常接近DDD的关键概念。

Summary I think the focus on data structures that are used to model the world (and are separated from the implementation that uses them) is very close to the key concepts of DDD.