Fundamentals 22 min read

An Introduction to Domain-Driven Design Patterns and Practices

This article explains the core concepts of Domain‑Driven Design, including model‑driven design, ubiquitous language, bounded contexts, layered and hexagonal architectures, and key building blocks such as entities, value objects, aggregates, repositories, factories, and services, to help developers build business‑centric enterprise applications.

Architects Research Society
Architects Research Society
Architects Research Society
An Introduction to Domain-Driven Design Patterns and Practices

Enterprise applications are complex and often focus on technical details like persistence, AJAX, and web services, but without solving business problems they are useless. Domain‑Driven Design (DDD), first described by Eric Evans, redirects attention to the core domain, distinguishing core and supporting sub‑domains.

DDD provides a set of patterns for building domain models. The model is the set of concepts implemented in code, not just diagrams, and code itself is the model. Visualizations such as UML class diagrams or entity‑relationship diagrams are merely views of the model.

Model‑driven design means that changes in the model lead to changes in the code and vice‑versa. While DDD does not force object‑orientation, most mainstream languages are OO, so models are expressed as classes and interfaces.

A ubiquitous language is cultivated between domain experts and developers, using the same terms from the domain model to discuss requirements, which helps expose missing concepts.

Every model exists within a bounded context (BC). Different BCs may interact via published language, open host services, shared kernel, consumer/provider, conformist, or anti‑corruption layer relationships, forming a spectrum of collaboration.

Strategic DDD involves mapping BCs and their dependencies to understand integration risks and opportunities.

Layered architecture places the domain layer at the center, surrounded by application, infrastructure, and presentation layers. However, strict linear dependencies can be problematic, leading many to adopt hexagonal (ports‑and‑adapters) architecture, where the domain sits at the core and interacts with the outside through well‑defined ports.

Key building blocks include:

Entities : mutable, often persisted objects with identity.

Value Objects : immutable objects that encapsulate concepts like Money or SocialSecurityNumber, providing value semantics.

Modules : packages or namespaces that keep the domain model decoupled.

Aggregates and Aggregate Roots : clusters of related entities with a single root that enforces invariants.

Repositories abstract persistence, returning aggregate roots and supporting multiple implementations (e.g., Hibernate, in‑memory). Factories create aggregates, often using interfaces to avoid circular dependencies.

Domain services contain business logic that does not naturally belong to an entity, while infrastructure services implement technical concerns such as email or PDF generation. Application services orchestrate use cases, invoking domain services, repositories, and infrastructure services, and mediate between the presentation layer and the domain.

Overall, DDD provides a comprehensive set of patterns to align software design with business requirements, reducing complexity and improving maintainability.

Figure 1: Model vs Views of the Model

Figure 2: Bounded Context Relationship Spectrum

Figure 3: Layered Architecture

Figure 4: Hexagonal Architecture

Money m1 = new Money("GBP", 10);
Money m2 = new Money("GBP", 20);
Money m3 = m1.add(m2);

Figure 5: Example of immutable Value Object usage.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Domain-Driven DesignDDDHexagonal Architecture
Architects Research Society
Written by

Architects Research Society

A daily treasure trove for architects, expanding your view and depth. We share enterprise, business, application, data, technology, and security architecture, discuss frameworks, planning, governance, standards, and implementation, and explore emerging styles such as microservices, event‑driven, micro‑frontend, big data, data warehousing, IoT, and AI architecture.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.