Skip to main content

Domain Model

 

What is the Domain Model in Domain Driven Design?

To understand Domain Driven Design, you really need to understand the terminology. However, I often find that terminology in the absence of real world context is not only difficult to understand, but almost impossible to apply and reap the benefits of.

Domain Model is a term you will hear a lot in Domain Driven Design. I think Domain Model is one of the most obvious examples of terminology that means absolutely nothing unless you understand the context in which it applies.

In today’s article we’re going to be looking at what Domain Model actually means, why it is important and how to use it within the context of your development projects.

The Domain is the problem

Domain Driven Design is predicated around the idea of solving the problems organisations face through code. This is achieved by focusing the investment of resources into the heart of the business logic of the application.

The domain therefore is, the world of the business. Whenever you hear the phrase “Domain Driven Design”, you should think of it as “Business Problem Driven Design”.

The domain is the world of the business you are working with and the problems they want to solve. This will typically involve rules, processes and existing systems that need to be integrated as part of your solution.

The domain is the ideas, knowledge and data of the problem you are trying to solve. Most businesses will have terms that have specific meaning within the context of their organisation. They will also likely have metrics, goals and objectives that are unique to their business.

All of the knowledge around the company and how it operates will form the domain of your Domain Driven Designed project.

The Model is your solution

The Model of an Domain Driven Designed project is your solution to the problem.

The Model usually represents an aspect of reality or something of interest. The Model is also often a simplification of the bigger picture and so the important aspects of the solution are concentrated on whilst everything else is ignored.

This means your Model should be focused knowledge around a specific problem that is simplified and structured to provide a solution.

The Domain Model

So if the Domain is the world of the business, and the Model is your solution, what is the Domain Model?

The Domain Model is your organised and structured knowledge of the problem. The Domain Model should represent the vocabulary and key concepts of the problem domain and it should identify the relationships among all of the entities within the scope of the domain.

The Domain Model itself could be a diagram, code examples or even written documentation of the problem. The important thing is, the Domain Model should be accessible and understandable by everyone who is involved with the project.

The Domain Model should also define the vocabulary around the project and should act as a communication tool for everyone involved. The Ubiquitous Language is an extremely important concept in Domain Driven Design and so it should be directly derived from the Domain Model.

One of the downfalls of many software development projects is the misunderstanding of terms, objectives and proposed solutions that are scoped at the beginning of development.

The Domain Model should act as a clear depiction of the problem that is being solved and the proposed solution. It is extremely important that all stakeholders of the project contribute to the Domain Model so that everyone understands the key concepts and definitions of the vocabulary of the project and how the problem is being tackled and solved.

Why is the Domain Model important?

So the Domain is the world of the business, the Model is your solution and the Domain Model is the structured knowledge of the problem.

Why is this important to Domain Driven Design? Well, I think there are three reasons why a Domain Model is important.

The Domain Model and the heart of the design shape each other

The code that you write should be intimately linked to the model of the problem you are solving. Anyone on the team should be able to look at your code and understand how it applies to the problem you are solving.

When developers deviate from the model, they write code that is built around their mental model of the problem. The code that you write should be directly derived from the agreed Domain Model to ensure that your solution meets the requirements of the business.

The Domain Model is the backbone of the language used by all team members

Every single person on the project team should use the Ubiquitous Language. This means that technical and non-technical people have a common language to communicate so there is no loss of understanding between parties.

The Ubiquitous Language should be directly derived from the Domain Model and so without a Domain Model you don’t have a Ubiquitous Language.

Without a Ubiquitous Language you will start to feel the friction of communication and the loss of understanding between technical and non-technical members of the team. If the code that is written starts to deviate away from the requirements of the business experts, the end solution won’t satisfy the goals of the project.

The Domain Model is distilled knowledge

The Domain Model should be the outcome of an iterative discovering process where everyone on the team meets to discuss the problem you are facing and how it should be solved.

This early collaboration between domain experts and the development team is critical to the success of the project.

The Domain Model should capture how you think about the project and all of the distilled knowledge that has been derived from those collaboration sessions.

Whenever a decision needs to be made during the course of the project everyone should refer to the Domain Model to look for the answer or to try to iteratively evolve the design to discover a hidden truth that has not previously been exposed.

How do you arrive at a Domain Model?

Arriving at a Domain Model is an iterative approach that attempts to discover the real problem that is faced and the correct solution that is required.

It’s important to focus a Domain Model on one important problem. Trying to capture the entire scope of a business inside of a single Domain Model will be far too overcomplicated and most likely contradictive as concepts and ideas move around the organisation.

The problem should be mapped out through talking to business experts to discover the problems they face. This should form the conceptual problem that you are looking to tackle.

Business experts won’t talk in the terms of technical solutions, and so it is your job to correctly interpret their problems into technical solutions.

During this process the important aspects of the problem should be picked out from the language and given concrete definitions to form the Ubiquitous Language.

It doesn’t really matter whether the Domain Model is created in code, as a diagram or in prose. However there should be a tight feedback loop where everyone on the project discusses the proposed Domain Model to get closer to the solution. This is an iterative approach that will likely encompass code, diagrams and prose to really understand the problem and to discover the correct solution.

What is an example of a Domain Model?

It’s difficult to show an example of a Domain Model as it should really be taken from a real world business problem.

However, for the benefit of this article, lets pretend we have the following business problem we need to solve:

  1. A business wants to create software to manage it’s projects
  2. Projects are derived from a product roadmap
  3. The project is picked due to certain criteria
  4. The project is assigned to a project manager
  5. The project manager organises the team
  6. The sprint is planned

The 6 steps that I’ve outlined above is the manually process that managers at a fictitious organisation walk through to assign tasks to employees. This is the Domain because it is solely focused on the world of the business.

The Model is focused on this one aspect of project management within the scope of the bigger organisation. In large organisations there are probably numerous ways that work is chosen and allocated to teams of employees. However in order to stay on track, we only care about this one, structured problem.

The Domain Model should take the Domain and the Model to form a a conceptual solution to the problem.

For example, we can see that we will probably need entities for RoadmapProject ManagersEmployeesTeam and Sprint.

We will need a way of selecting projects from some kind of persistence storage.

We will need a way of capturing the business logic of Criteria to make decisions of priority based upon what is important to the business.

And finally we will need a way of planning a sprint and allocating times and resources to ensure that the work is completed.

I’m sure if this was a real world problem we would need to explore the concept of assigning projects in much greater detail, but hopefully you see what I’m getting at.

Conclusion

The Domain Model is the important starting point when taking on a Domain Driven Design project. Domain Driven Design is all about solving the problems of an organisation, and so the Domain Model is all about understanding and interpreting the important aspects of a given problem.

The Domain Model represents the Ubiquitous Language of the project, the important concepts and the relationships between those concepts.

The Domain Model should also be used as a way to validate as to whether everyone on the team understands the problem. A Domain Model will focus attention on a specific problem and it will define the vocabulary and the context of the important things that need to be considered.

Arriving at a solid Domain Model for a given problem is an iterative approach of collaboration between the business experts and the technical team. It should act as a source of truth for the project and it is a living document as the project progresses.

Comments

Popular posts from this blog

Apache Spark Discretized Streams (DStreams) with Pyspark

Apache Spark Discretized Streams (DStreams) with Pyspark SPARK STREAMING What is Streaming ? Try to imagine this; in every single second , nearly 9,000 tweets are sent , 1000 photos are uploaded on instagram, over 2,000,000 emails are sent and again nearly 80,000 searches are performed according to Internet Live Stats. So many data is generated without stopping from many sources and sent to another sources simultaneously in small packages. Many applications also generate consistently-updated data like sensors used in robotics, vehicles and many other industrial and electronical devices stream data for monitoring the progress and the performance. That’s why great numbers of generated data in every second have to be processed and analyzed rapidly in real time which means “ Streaming ”. DStreams Spark DStream (Discretized Stream) is the basic concept of Spark Streaming. DStream is a continuous stream of data.The data stream receives input from different kind of sources like Kafka, Kinesis...

6 Rules of Thumb for MongoDB Schema Design

“I have lots of experience with SQL and normalized databases, but I’m just a beginner with MongoDB. How do I model a one-to-N relationship?” This is one of the more common questions I get from users attending MongoDB office hours. I don’t have a short answer to this question, because there isn’t just one way, there’s a whole rainbow’s worth of ways. MongoDB has a rich and nuanced vocabulary for expressing what, in SQL, gets flattened into the term “One-to-N.” Let me take you on a tour of your choices in modeling One-to-N relationships. There’s so much to talk about here, In this post, I’ll talk about the three basic ways to model One-to-N relationships. I’ll also cover more sophisticated schema designs, including denormalization and two-way referencing. And I’ll review the entire rainbow of choices, and give you some suggestions for choosing among the thousands (really, thousands) of choices that you may consider when modeling a single One-to-N relationship. Jump the end of the post ...

Khác nhau giữa các chế độ triển khai giữa Local, Standalone và YARN trong Spark

Trong Apache Spark, có ba chế độ triển khai chính: Local, Standalone và YARN. Dưới đây là sự khác biệt giữa chúng: Chế độ triển khai Local: Chế độ triển khai Local là chế độ đơn giản nhất và được sử dụng cho môi trường phát triển và kiểm thử. Khi chạy trong chế độ Local, Spark sẽ chạy trên một máy tính duy nhất bằng cách sử dụng tất cả các luồng CPU có sẵn trên máy đó. Đây là chế độ phù hợp cho các tác vụ nhỏ và không yêu cầu phân tán dữ liệu. Chế độ triển khai Standalone: Chế độ triển khai Standalone cho phép bạn triển khai một cụm Spark độc lập bao gồm nhiều máy tính. Trong chế độ này, một máy tính được chọn làm "Spark Master" và các máy tính khác được kết nối với Spark Master như là "Spark Workers". Spark Master quản lý việc phân phối công việc và quản lý tài nguyên giữa các Spark Workers. Chế độ Standalone phù hợp cho triển khai Spark trên các cụm máy tính riêng lẻ mà không có hệ thống quản lý cụm chuyên dụng. Chế độ triển khai YARN: YARN (Yet Another Resource N...