In a design meeting for an order feature, a developer proposes starting with an Order class.
The planner asks you to distinguish between an "order sheet" and a "payment record."
If you start implementing with different people understanding the same word differently, you will end up renaming classes and changing relationships many times later.
A
domain model
is a tool that organizes the concepts of the business and their relationships before software is built.
It uses the same notation as UML class diagrams, but what it depicts is different.
A domain model is not a set of software classes ๐
A domain model shows the important
concepts
(conceptual classes) in the problem domain and the relationships between them.
Concepts are the things that appear in the actual business.
Customer, order, order line, and product are examples.
By contrast, classes created for implementation, such as OrderService or OrderRepository, do not belong in the domain model.
Leave out methods and framework details, and keep only the business terms and their relationships.
๐
If you move conceptual classes directly into database tables or service classes, the business meaning can easily get buried under technical structure.
Keep the domain model as a picture for understanding the business, and move it into the design as a separate step.
A simple starting point for a domain model is the sentences of a use case.
Take the following sentence as an example.
A customer puts products into the shopping cart, confirms the order, and then pays by card.
Pulling out the nouns gives customer, product, shopping cart, order, card, and payment.
Not every noun becomes a conceptual class, so write down the reason for each candidate.
Candidate
Decision
Reason
Customer
Keep as a concept
The business actor who places the order
Product
Keep as a concept
The business object that is ordered
Shopping cart
Review, then keep
A list held before ordering, handled separately in the business
Order
Keep as a concept
The business unit that bundles the customer's request
Card
Convert to an attribute
Information about the payment method, with little behavior of its own
Payment
Keep as a concept
The business unit that records payment approval and its result
System
Exclude
The subject of the analysis itself, so it is not a concept
Turning "card" into an attribute is the result of a judgment.
If the requirements say that card information must be managed independently, for example by storing several cards or tracking expiry dates separately, keep it as a concept.
Once the candidates are organized, draw the relationships between the concepts.
In the order example, the following relationships appear.
A customer can place orders many times. Each order is linked to one customer.
An order contains several order lines. Each order line refers to one product.
A payment is recorded for an order. In this example, we assume that each order has at most one payment record.
A domain model where a customer places many orders, an order holds many order lines, each order line refers to one product, and a payment is linked to the order
The number at the end of a relationship line is its
multiplicity
.
1 means exactly one, * means many, and 0..1 means zero or one.
Changing a single notation changes the design, so always check it against the business rules.
Do the names match the terms used in the business?
Does the multiplicity match the actual business rules?
Have technical concepts crept in?
For example, a model that has only an order total and no order lines cannot express a requirement to change the quantity of each product.
This problem becomes visible when you review the "change quantity" use case against the model.
๐จโ๐ป
If you write the use cases first and then draw the domain model, it is easier to find missing concepts.
If you start from a class diagram, technical objects that do not exist in the business tend to slip in.
of the business, so that developers and planners talk in the same terms.
Find candidates in the nouns of the use cases, filter them with written reasons, and then check the multiplicities. That gives the design a solid starting point.