Programmers develop each piece of software for a specific domain, for example:
- An analytics system might work with view, session, funnel, and cohort
- The concepts will be different in an online store — product, category, and payment gateway
Together they form the. You can find the term category model in some sources. It is the same as ontology. In addition to the concepts themselves, ontologies include descriptions of their relationships. For example, the User entity relates to the Purchase entity in a one-to-many relationship. It means users can make any number of purchases, but each purchase belongs to only one user.
The domain model is the basis for communication and understanding between team members. It doesn't depend on the programming language or programming in general. It doesn't matter who is communicating — programmers with each other or programmers with customers, managers, or designers, it's all the same. You work with the domain's entities and relationships and the business rules used in that program.
Such rules may include automatically including a discount when ordering a certain amount of goods:
It's important to understand that the model reflects only a part of the domain in some detail. And the model can vary in programs written by different developers, even if they're from the same field.
Some domains have a set of fixed entities, relationships, and rules of operation. We can see it in accounting, for example. But there are also less formal areas where there are even more possibilities. Here are some examples from Hexlet. The number of entities is more than a hundred, the number of links is several hundred, and the number of rules is difficult to count. There are so many of them too.
We create a data model in code based on the domain model. We construct entities and define their relationships. Then we build a working code that operates on the entities based on requirements and business rules. You may be wondering how to map these entities to the database where they're stored.
The easiest way is to create a table for each entity and link them with foreign keys. Most projects do this. We can do it by the Object Relational Mapper (ORM) — a data framework.
The ORM helps describe entities and their relationships and determines how the entity is mapped to the database (usually semi-automatically). The ORM takes care of a part of the work: