DDDDDD
DDDDDD
16 languages
• Article
• Talk
• Read
• Edit
• View history
Tools
•
•
•
•
•
•
•
•
•
•
•
•
•
Appearance
hide
Text
•
Small
Standard
Large
Width
•
Standard
Wide
Color (beta)
•
Automatic
Light
Dark
From Wikipedia, the free encyclopedia
Part of a series on
Software development
show
Core activities
show
show
show
Supporting disciplines
show
Practices
show
Tools
show
show
Glossaries
show
Outlines
• v
• t
• e
Under domain-driven design, the structure and language of software code (class
names, class methods, class variables) should match the business domain. For
example: if software processes loan applications, it might have classes like "loan
application", "customers", and methods such as "accept offer" and "withdraw".
Domain-driven design is predicated on the following goals:
• placing the project's primary focus on the core domain and domain logic layer;
• basing complex designs on a model of the domain;
• initiating a creative collaboration between technical and domain experts to iteratively
refine a conceptual model that addresses particular domain problems.
Critics of domain-driven design argue that developers must typically implement a great
deal of isolation and encapsulation to maintain the model as a pure and helpful
construct. While domain-driven design provides benefits such as maintainability,
Microsoft recommends it only for complex domains where the model provides clear
benefits in formulating a common understanding of the domain.[4]
The term was coined by Eric Evans in his book of the same name published in 2003.[5]
Overview
[edit]
Of primary importance is a domain of the software, the subject area to which the user
applies a program. Software's developers build a domain model: a system of
abstractions that describes selected aspects of a domain and can be used to solve
problems related to that domain.
In domain-driven design, the domain layer is one of the common layers in an object-
oriented multilayered architecture.
Kinds of models
[edit]
This article needs additional citations for verification. Please help improve
this article by adding citations to reliable sources. Unsourced material may be
challenged and removed.
Find sources: "Domain-driven design" –
news · newspapers · books · scholar · JSTOR (July 2023) (Learn how and when to
remove this message)
Models can also define events (something that happened in the past). A domain event
is an event that domain experts care about. Models can be bound together by a root
entity to become an aggregate. Objects outside the aggregate are allowed to hold
references to the root but not to any other object of the aggregate. The aggregate root
checks the consistency of changes in the aggregate. Drivers do not have to individually
control each wheel of a car, for instance: they simply drive the car. In this context, a car
is an aggregate of several other objects (the engine, the brakes, the headlights, etc.).
In domain-driven design, an object's creation is often separated from the object itself.
A repository, for instance, is an object with methods for retrieving domain objects from a
data store (e.g. a database). Similarly, a factory is an object with methods for directly
creating domain objects.
When part of a program's functionality does not conceptually belong to any object, it is
typically expressed as a service.
Similarly, the naked objects pattern holds that the user interface can simply be a
reflection of a good enough domain model. Requiring the user interface to be a direct
reflection of the domain model will force the design of a better domain model.[7]
While CQRS does not require domain-driven design, it makes the distinction between
commands and queries explicit with the concept of an aggregate root. The idea is that a
given aggregate root has a method that corresponds to a command and a command
handler invokes the method on the aggregate root.
The aggregate root is responsible for performing the logic of the operation and either
yielding a failure response or just mutating its own state that can be written to a data
store. The command handler pulls in infrastructure concerns related to saving the
aggregate root's state and creating needed contexts (e.g., transactions).
Event sourcing
[edit]
Event sourcing is an architectural pattern in which entities track their internal state not
by means of direct serialization or object-relational mapping, but by reading and
committing events to an event store.
When event sourcing is combined with CQRS and domain-driven design, aggregate
roots are responsible for validating and applying commands (often by having their
instance methods invoked from a Command Handler), and then publishing events. This
is also the foundation upon which the aggregate roots base their logic for dealing with
method invocations. Hence, the input is a command and the output is one or many
events which are saved to an event store, and then often published on a message
broker for those interested (such as an application's view).
Modeling aggregate roots to output events can isolate internal state even further than
when projecting read-data from entities, as in standard n-tier data-passing architectures.
One significant benefit is that axiomatic theorem provers (e.g. Microsoft Contracts and
CHESS[10]) are easier to apply, as the aggregate root comprehensively hides its internal
state. Events are often persisted based on the version of the aggregate root instance,
which yields a domain model that synchronizes in distributed systems through optimistic
concurrency.
Notable tools
[edit]
Although domain-driven design does not depend on any particular tool or framework,
notable examples include: