As a developer, you may think that your job is to write code. However, Software development is not a product pipeline. If all developers just simply add new features and don’t care about design, software development and maintenance will become more and more complicated. A developer’s job is to solve a problem through software, and coding is just one aspect of software development. Good design and communication are just as important.

Domain driven design(or DDD) is such approach focused on clear communication and shared domain knowledge.

The importance of the shared model knowledge

Before attempting to solve a problem it’s important that we understand the problem correctly. Obviously, if our understanding of the problem is incomplete or distorted, then we won’t to be able to provide a useful solution. And sadly, of course, it’s the developers’ understanding, not the domain experts’s understanding. that gets released to production.
What if the domain experts,the development team, other stakeholders share the same model? In this case there is no translation from the domain expert’s requirements to the code. The code is designed to reflect the shared model directly.

The benefits of this approach can be:

  • Faster time to market
  • More business value
  • Less waste
  • Easier maintenance and evolution

Understanding the Domain through business events

A DDD approach to gathering requirements will emphasize building a shared understanding between developers and domain experts.
How to do that? Business logic is not static, it’s a process of transformation, so understanding how it changes is a good starting point. the transformation point of the process is also called domain event. For example “the order submitted” is a domain event will kick off the order selling process.

Use Event storming to discover the domain

There are a number of ways to discover events in a domain, but one that is particularly suitable for a DDD approach is Event Storming, which is a collaborative process for discovering business events and their associated workflows. TW Xi’an team did several workshops for Event Storming in the past days.

Partitioning the Domain into Subdomains

After Event storming we have a good understanding of what the various business processes are. But the big picture is still quite chaotic. The next step is partitioning the problem domain into smaller subdomains When faced with a large problem, it’s natural to break it into smaller components that can be addressed separately.
We have a large problem: Selling domain, Can we break it into smaller pieces?
Yes, we can. We can split it to various aspects of the Order, Charge, Authentication, Availability …, We will call each of these areas a domain.

Creating a solution Using Bounded contexts

Understanding the problem doesn’t mean that building a solution is easy. The solution can’t possibly represent all the information in the original domain. We should only capture the information that is relevant to solving a particular problem. Everything else is irrelevant.
We therefore need to create a distinction between a “problem space” and a “solution space” and they must be treated as two different things. To build the solution we will create a model for the problem domain, extracting only the aspects of the domain that are relevant and then re-creating them in our solution space as bounded context.

1. Why context

Because each context represents some specialized knowledge in the solution. Within the context, we share a common language and the design is coherent and unified.

2. Why bounded

In the real world, domains have fuzzy boundaries, but in the world of software we want to reduce coupling between separate subsystems so that they can evolve independently.

Creating a ubiquitous language

The set of concepts and vocabulary that is shared between everyone on the team is called the Ubiquitous Language. This is the language that defines the shared model for the business domain. The language should used everywhere in the project, not just in the requirements but in the design, and most importantly, in the source code.
Finally, it’s important to realize that you often cannot have a single Ubiquitous language that covers all domains and contexts.
We called User in Authentication domain but called Customer in Order domain.

Domain modeling

We have now got a basic understanding of Domain, but how to document them?
we should use visual diagrams, but these are often hard to work with and not detailed enough to capture some of the subtleties of the domain.
If you have a lot of database experience, your first instinct might be think about tables and the relationships between them. You might envision a Order table, an order line table, and Customer, Contact tables. And then you’ll probably want to describe the relationships between them by foreign key, But if you do this, you are making a mistake. In DDD we let the domain drive the design, not a database schema.
In DDD terminology this step called Domain modeling, For developer we should use code to modeling these domains.

Other concepts

As you know DDD is a large topic, We can not describe all the concepts in here. But you should understand that the core idea of DDD is using code to create a business model that can be shared with domain experts.
Other concepts like Entity, ValueObject, AggregateRoot, CQRS, EventSourcing, MicroService etc require you constantly practice to understand.

Layered architecture

For implementing DDD, we need to design our architecture to achieve this goal. The reason we will split whole system into multiple layers is Separation of Concerns and Single Responsibility Principle. The general idea is that we split persistence, rendering api and application logic to different layers and let developers focus on design and writing domain logic.

Domain Layer

We have the domain layer and business logic at the center, The domain layer will contain enterprise business logic and types.

Application Layer

Contains application logic and types.
The difference between Domain layer and application layers is Domain layer can be invoked by application layer, But domain layer don't know application layer.

Infrastructure Layer

Focus on persistence by database or api

Invert of Control

We don't want to let business logic to be dependent on concerns such as infrastructure and persistence so we invert these dependencies, so infrastructure, persistence and presentation all take a dependency on that center area.
The way we did is we added our abstraction and interfaces inside the core and then infrastructure and persistence implement those abstractions. For example, for persistence, if we were creating a repository there, there would be an IRepository used in the core and in persistence we will implement that IRepository. The result of this design is domain layer doesn't have any dependency on anything, We will got below benefit:

  • It's highly testable, We can actually test the core without UI
  • It's independent of persistence, whatever you persist data by database or api
  • Independent of external system

Why DDD and layered architecture的更多相关文章

  1. 2.2 DDD Layers & Clean Architecture DDD分层和简洁架构

    DDD Layers & Clean Architecture DDD分层和简洁架构 There are four fundamental layers of a Domain Driven ...

  2. Layered Architecture 分层架构

    分层的价值在于每一层都只代表程序中的某一特定方面.这种限制使每个方面的设计都更具有内聚性,更容易解释. 大多数成功的架构使用的都是包括下面这四个概念层的某个版本

  3. NLayer Architecture in abp

    https://aspnetboilerplate.com/Pages/Documents/NLayer-Architecture Introduction The layering of an ap ...

  4. WCF - Architecture

    WCF - Architecture WCF has a layered architecture that offers ample support for developing various d ...

  5. 架构:The Onion Architecture : part 3(洋葱架构:第三篇)(转载)

    In my previous installments, I described what has become my approach to defining the architecture fo ...

  6. 架构:The Onion Architecture : part 1(洋葱架构:第一篇)(转载)

    原文地址:http://jeffreypalermo.com/blog/the-onion-architecture-part-1/. I've spoken several times about ...

  7. Architecture Patterns

    This chapter provides guidelines for using architecture patterns. Introduction Patterns for system a ...

  8. MASA Framework - DDD设计(2)

    目录 MASA Framework - 整体设计思路 MASA Framework - EventBus设计 MASA Framework - MASA Framework - DDD设计(1) MA ...

  9. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

随机推荐

  1. C语言中数组使用负数值的标记

    ·引 对数组的认知 在c语言中,我们经常使用的一个结构便是数组,在最开始学习数组的时候,它被描述成这样(以一维二维数组为例):一维数组是若干个数连续排列在一起的集合,我们可以通过0-N的标记(N为数组 ...

  2. 2018-2019-2 网络对抗技术 20162329 Exp6 信息搜集与漏洞扫描

    目录 Exp6 信息搜集与漏洞扫描 一.实践原理 1. 间接收集 2. 直接收集 3. 社会工程学 二.间接收集 1. Zoomeye 2. FOFA 3. GHDB 4. whois 5. dig ...

  3. 信息学奥赛辅导经验谈 & 问题教学法中的学生思维能力培养

    转载来自朱全民名师工作室 信息学奥赛辅导经验谈 全国青少年信息学奥林匹克分区竞赛(简称NOI)是经中国科协.国家教育部批准,由中国计算机学会主办的一项全国性的青少年学科竞赛活动.随着信息学奥林匹克竞赛 ...

  4. Java当中的IO三

    1.处理流的使用实例 bufferedReader(处理流)介绍: buffereReader属于字符流,其次也是处理流,也是输入流,即字符输入处理流 常用方法 readLine() Buffered ...

  5. node01

    ---恢复内容开始--- 1.node初体验 安装完成node,写好相应的js代码后,在cmd中node 文件名即可完成编译执行过程. 2.尝试使用node搭建一个简单服务器 //引入http模块 c ...

  6. tyflow birth节点

    0-50帧,持续出生5颗粒子,若范围为0-0,5颗粒子将在第一帧全部出生 每一帧出生5颗粒子,直到50帧结束 连续发射,在0-500帧范围内,每5颗粒子出生后,继续出生5颗 5颗粒子出生后持续50帧, ...

  7. tyflow车撞墙测试

  8. Nginx的虚拟主机配置

    虚拟主机技术能够让同一台服务器.同一组Nginx进程上运行多个网站,降低了资金和服务器资源的损耗.Nginx可以配置三种类型的虚拟主机,本文就是主要介绍这三种虚拟主机配置方式. 配置基于IP的虚拟主机 ...

  9. [LeetCode] Peak Index in a Mountain Array 山形数组的顶峰坐标

    Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists som ...

  10. python print 中文重定向失败

    一直以来认为解决python字符集编码,不一定需要通过sys.setdefaultencoding.因为既然python实现过程中,默认禁用了该操作,说明是不推荐的. 通过不断的字符转换,也cover ...