Tactical Domain Driven Design

BLOG
X
min read

In the previous article, we talked about strategic design and how it helps us construct bounded contexts, and its relationships. In the next section we will talk about Tactical design.

Tactical Design

Tactical design is a set of tools that helps construct a Domain model for each Bounded context. It helps clarify Business entities and result in a decoupled architecture.

Model Driven Design

Each model can be expressed when translated to a working code as a Service. Its purpose is to serve a single Aggregate. A design that is implemented using a domain model is called Model Driven Design.

Layered Architecture

Creating applications that can handle very complex tasks requires separation of concerns. This is where the concept of Layered Architecture comes in. The basic idea is to structure an application into four conceptual layers.

The “Request Handlers” layer accepts request and passes the needed objects to the right controllers. “Controllers” manage transactions, translates Data Transfer Objects (DTOs) and coordinates application activities. The “Business” layer implements the more domain specific logic. The “Persistence” layer is where the connection to the Data layer is made for persistence purposes. This allows your service to accept requests faster. It is organized, well defined, flexible, reusable, and well maintained

Value Objects

A general-purpose value object is designed to handle complexities and force ubiquitous language.

A well-designed value object has these properties:

  • Does not care about uniqueness
  • Always immutable
  • Rich in domain logic
  • Auto Validating
  • Has strong equality
  • Thread safe

Entities

Entities consist of value objects. They must be uniquely identified by an Id, and we must be able to persist it as a row in a Database. They are typically mutable and must implement some business logic.

Aggregates

Aggregates are a collection of entities and values which come under one transaction boundary. The must have a root entity in which this root entity controls the existence of the aggregate, meaning that if the root entity does not exist, the aggregate does not exist as well. The root entity governs the lifetime of the other entities in the aggregate.  

Repositories and Factories

Repositories help you persist aggregates, and that is why there must be one repository per aggregate. Repositories contain the logic behind persisting your aggregates.

Factories help create new aggregates.  

Tactical design overview

Strategic Domain Driven Design

Building a smart home

To help clarify how DDD design works in real life, let us take an example. We are required to build a full featured smart home. The contractor says that he wants to build a very well-structured smart home and he needs most of the components to be able to communicate with each other. You start implementing right away, and you find out that there are so many questions that needs to be asked. First thing we need to know is what kind of home are we talking about. Is it a one-bedroom apartment, a condo, a standalone apartment, a Villa, or a mansion. What is the kind of components do we need. How many rooms are there, and what type of rooms?

You go back to the contractor and ask him some questions. Two hours into the conversation, you feel overwhelmed by how complex this is getting. So, you go bring your Domain Expert. A domain expert is typically someone who worked on a similar matter before. He has the required business experience that can be useful to speed up this process and understand the complexity well.

Our main Domain is now a Smart Villa. We break down our components until we settle on our bounded contexts. Here is a diagram showing all our BCs

Each component in this diagram can represent a BC. It should have its own value objects, entities, aggregate, etc.

Let us take the lighting for example.

First we create a root entity that can model the Lighting in the right context. The first rule is to never use primitive data types, and instead we composite many value objects that are self-explanatory in terms of language.  

Imagine if we use float for brightness for example. This will force our Lighting entity to deal with all changes. If we want to modify the brightness class to add  intensity and color, we then only have to modify in the Brightness class as opposed to modifying the whole entity. That is the reason they are called value objects. They are objects that provide value and encapsulate a certain logic that can be described by a ubiquitous language. Any property for an entity that you can describe should be its own class, and then added as an entity variable.

We are now able to see how DDD came to benefit us in designing our classes. Because we could define our domain and sub-domains, we could easily create our domain model which encapsulated several BCs and defined the relationships between them.

We then could create our Ubiquitous language that made us able to name our value objects. These value objects helped us construct a well-structured entity that is consistent and easily understandable because it follows our language standards.  

Now let us implement a method that adjusts the brightness.

This is a simple method that takes a float as an input and adjust the brightness accordingly. It first validates that the maximum intensity for the light is not violated, sets the brightness, and then returns the “this” object. We can now notice how the abstraction and intensive use of value objects helped us encapsulate our logic in an organized way.

Summary

Use Domain-Driven Design to collaborate among all project disciplines and clearly understand the business requirements.

Establish a Ubiquitous Language to discuss domain related concepts.

Use Bounded Contexts to break down complex domains into manageable parts.

Implement a Layered Architecture to focus on different aspects of the application.

Modernizing Legacy Apps​

Maecenas mollis sagittis ante, eleifend ultricies sapien. Nam ultricies risus et augue auctor vulputate gravida eget sem. Quisque mollis gravida magna, eu semper eros pharetra in. Sed et elit sit amet odio rutrum consectetur vel vel ante. Praesent vitae elementum lacus. Vivamus efficitur nunc tortor, cursus lobortis purus placerat ut. Maecenas ut aliquet ante, vel finibus lorem. Nulla facilisi. Donec maximus elementum pulvinar.

test heading

h1 text

h3

Impact

Sample article featured image
Pellentesque posuere sem in ipsum venenatis, at bibendum lorem aliquam. Nullam condimentum tempus orci nec commodo. Maecenas malesuada elementum metus, non aliquam est elementum sed. Integer ac finibus ligula, id venenatis lectus. Mauris non eleifend enim. Pellentesque eu congue justo. In ornare dapibus nisi, sit amet feugiat neque. Vivamus mollis, lectus quis gravida viverra, risus ligula congue felis, ut laoreet sem nisi in tortor. Sed vel ligula nulla.
“Quisque mollis purus nec pulvinar rutrum. Duis faucibus sed orci vel pellentesque. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec non volutpat eros, nec placerat mi. Praesent porta felis ut urna sagittis, sit amet placerat nisl porttitor.”

Nunc tempor molestie velit id dictum. Aenean ac venenatis ipsum, sit amet sodales tortor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque posuere sem in ipsum venenatis, at bibendum lorem aliquam.

Nullam condimentum tempus orci nec commodo. Maecenas malesuada elementum metus, non aliquam est elementum sed. Integer ac finibus ligula, id venenatis lectus. Mauris non eleifend enim. Pellentesque eu congue justo. In ornare dapibus nisi, sit amet feugiat neque. Vivamus mollis, lectus quis gravida viverra, risus ligula congue felis, ut laoreet sem nisi in tortor. Sed vel ligula nulla.

data-acc-source-start

Ensure that Modernizing your Legacy Application is the Right Decision

Our expert consultants work closely with you to understand you organization's business drivers, then conduct an in-depth business goals and that every dollar invested is directed towards the right solution

Depend on a Tailored, Phased Application Modernization Strategy

Our expert consultants work closely with you to understand you organization's business drivers, then conduct an in-depth business goals and that every dollar invested is directed towards the right solution

Streamline the Transition from Old to New

Our expert consultants work closely with you to understand you organization's business drivers, then conduct an in-depth business goals and that every dollar invested is directed towards the right solution

data-acc-source-end

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elementum, elit a pellentesque placerat, nisl quam blandit orci, at maximus eros nunc nec lacus. Nullam euismod consequat libero, eget suscipit ligula lacinia nec. Nunc finibus dapibus quam, eu convallis magna. Nulla finibus ut risus in sodales. Cras tristique nisi non mattis volutpat. Nullam venenatis varius nisl, dictum ornare lorem dictum rhoncus. Nulla sem nunc, lobortis et massa sed, ultrices convallis justo. Quisque laoreet nibh sit amet arcu rhoncus accumsan. Proin at elementum lacus, at maximus mi. Curabitur vulputate urna mollis lacinia auctor. Donec venenatis finibus magna id tempor. Duis at mattis odio. Aenean eu tempus justo. Donec est arcu, vulputate quis risus et, pharetra imperdiet velit.

Vivamus ut dignissim quam.

No items found.
Article carousel image 1
Article carousel image 2
Article carousel image 3
Author
Youssef Refaat
Posted on
21 Jun 2023
We’re your partner in addressing

real human needs.

Align IT Initiatives with Strategic Business Goals
Plus sign iconMinus sign icon
10X
Increase in transactions
per second

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Modernizing Legacy Apps​

Maecenas mollis sagittis ante, eleifend ultricies sapien. Nam ultricies risus et augue auctor vulputate gravida eget sem. Quisque mollis gravida magna, eu semper eros pharetra in. Sed et elit sit amet odio rutrum consectetur vel vel ante. Praesent vitae elementum lacus. Vivamus efficitur nunc tortor, cursus lobortis purus placerat ut. Maecenas ut aliquet ante, vel finibus lorem. Nulla facilisi. Donec maximus elementum pulvinar.

Impact

Sample article featured image
Pellentesque posuere sem in ipsum venenatis, at bibendum lorem aliquam. Nullam condimentum tempus orci nec commodo. Maecenas malesuada elementum metus, non aliquam est elementum sed. Integer ac finibus ligula, id venenatis lectus. Mauris non eleifend enim. Pellentesque eu congue justo. In ornare dapibus nisi, sit amet feugiat neque. Vivamus mollis, lectus quis gravida viverra, risus ligula congue felis, ut laoreet sem nisi in tortor. Sed vel ligula nulla.
“Quisque mollis purus nec pulvinar rutrum. Duis faucibus sed orci vel pellentesque. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec non volutpat eros, nec placerat mi. Praesent porta felis ut urna sagittis, sit amet placerat nisl porttitor.”

Nunc tempor molestie velit id dictum. Aenean ac venenatis ipsum, sit amet sodales tortor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque posuere sem in ipsum venenatis, at bibendum lorem aliquam.

Nullam condimentum tempus orci nec commodo. Maecenas malesuada elementum metus, non aliquam est elementum sed. Integer ac finibus ligula, id venenatis lectus. Mauris non eleifend enim. Pellentesque eu congue justo. In ornare dapibus nisi, sit amet feugiat neque. Vivamus mollis, lectus quis gravida viverra, risus ligula congue felis, ut laoreet sem nisi in tortor. Sed vel ligula nulla.

data-acc-source-start

Ensure that Modernizing your Legacy Application is the Right Decision

Our expert consultants work closely with you to understand you organization's business drivers, then conduct an in-depth business goals and that every dollar invested is directed towards the right solution

Depend on a Tailored, Phased Application Modernization Strategy

Our expert consultants work closely with you to understand you organization's business drivers, then conduct an in-depth business goals and that every dollar invested is directed towards the right solution

Streamline the Transition from Old to New

Our expert consultants work closely with you to understand you organization's business drivers, then conduct an in-depth business goals and that every dollar invested is directed towards the right solution

data-acc-source-end

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elementum, elit a pellentesque placerat, nisl quam blandit orci, at maximus eros nunc nec lacus. Nullam euismod consequat libero, eget suscipit ligula lacinia nec. Nunc finibus dapibus quam, eu convallis magna. Nulla finibus ut risus in sodales. Cras tristique nisi non mattis volutpat. Nullam venenatis varius nisl, dictum ornare lorem dictum rhoncus. Nulla sem nunc, lobortis et massa sed, ultrices convallis justo. Quisque laoreet nibh sit amet arcu rhoncus accumsan. Proin at elementum lacus, at maximus mi. Curabitur vulputate urna mollis lacinia auctor. Donec venenatis finibus magna id tempor. Duis at mattis odio. Aenean eu tempus justo. Donec est arcu, vulputate quis risus et, pharetra imperdiet velit.

Vivamus ut dignissim quam.

No items found.
Article carousel image 1
Article carousel image 2
Article carousel image 3
Author
This is some text inside of a div block.
Posted on
This is some text inside of a div block.
Topics