Demystifying Ddd a Practical Guide

Domain Driven Design

Demystifying Ddd a Practical Guide


Introduction

/img/demystifying-ddd-a-practical-guide/Domain-driven-design.en.png

DDD is a software design approach that aims to create systems that truly reflect business needs by focusing on the application domain. Instead of starting with the technology, DDD proposes that we start by understanding the problem we want to solve, i.e. the domain.

What is a domain?

In DDD, the domain is the “heart” of the business, the problem that the software proposes to solve. It encompasses all the processes, rules and peculiarities of the business. For example, in a banking system, the domain might include areas such as investments, cards, bank accounts and loans.

The 3 Pillars of DDD

DDD is based on three main pillars:

  • Ubiquitous Language: The creation of a common vocabulary between developers and domain experts (people who know the business in depth). This language should be used in all conversations, documentation and code. For example, in a library system, everyone should understand what “loan”, “book”, “user” mean.
  • (Bounded Contexts: In large projects, it is common to have different areas with their own rules and peculiarities. Bounded Contexts serve to break down a complex domain into smaller parts, where a specific model is defined and applicable. Each context has its own ubiquitous language, and the boundaries are defined to prevent the complexity of one context from contaminating another.
  • Context Mapping: The Context Map shows how the different Delimited Contexts relate to each other. It defines the connections and interactions between these contexts, helping to understand how the system works as a whole. For example, in an e-commerce system, the product catalog, shopping cart and payment contexts are interconnected, but each has its own responsibilities.

Strategic and Tactical Design

DDD is divided into two approaches:

  • Strategic Design: Defines the overall scenario of the system. This includes identifying the domains, subdomains, delimited contexts and the relationships between them. It’s like planning the architecture of a building, defining which areas will exist and how they will connect.
  • “Tactical Design:” After the strategic phase, Tactical Design comes into play with a focus on implementing the product. It is responsible for modeling the domain within a delimited context, using patterns such as entities, value objects, services, aggregates and repositories. It’s like building each room in a building, choosing the materials and the layout of the furniture.

What are DDD’s Building Blocks?

They are the domain objects, i.e. entities, value objects, services, aggregates and repositories.

  • Entities: Objects with a unique identity that persist over time, for example, a customer or a product.
  • Value Objects: Objects with no identity, described by their attributes, such as an address or a date.
  • Services: Operations that do not belong to a specific entity or value object.
  • Aggregates: Collections of entities and value objects treated as a unit, with a root object that controls access to the internal objects.
  • Repositories: Abstract data access, allowing the domain to focus on business logic.

Advantages of DDD

  • *Business alignment: DDD promotes clear communication between developers and domain experts, ensuring that the software really does solve business problems.
  • More flexible and maintainable software: The delimited contexts and separation of responsibilities make the software more adaptable to change.
  • Cleaner and more reliable code: The use of design patterns and a common language results in code that is easier to understand and maintain.
  • Focus on the main problem: DDD helps the team focus on what really matters, which is the business domain, avoiding detour into technical details.

Conclusion

DDD is a powerful approach to developing complex software. By focusing on the business domain, DDD ensures that the software is built to meet the real needs of the users. Although it can be challenging at first, the benefits in terms of business alignment, flexibility and code quality are well worth the effort. If you’re looking to create software that generates real value for your customers, DDD could be the way to go. Remember that DDD is not a silver bullet. You need to analyze each scenario to see if it fits the needs of your project. I hope this article helps you start your journey into the world of DDD! If you need more details on any specific point, let me know!

DDD