Search code examples
oopdomain-driven-design

Domain-Driven Design: Is a Subdomain a class?


Let's consider that we use OOP.

Is a Subdomain a class? And Bounded Context is a set of classes that are used together for the only purpose(ideally)? Can on subdomain contain a set of classes? If yes, then what is the difference between Bounded Context?

For example, we have a domain: Online shop.

We divide Online Shop in 2 subdomains: Customer Support and Shopping.

We see that such a division is still huge, so we divide:

  1. Customer Support in Customer, Supporter, Ticker subdomains. Now such subdomains become classes, and the divided subdomain becomes a bounded context.
  2. Shopping in Customer, Cart, Payment subdomains. Now such subdomains become classes, and the divided subdomain becomes a bounded context.

Probably it's not the best example of subdomains, but the point is to give you understanding of my problem.


Solution

  • I will try to explain, you are mixing things.

    • Subdomain. It belongs to the problem space. Here you don't have classes or anything about a programming language. You have concepts, relationships, etc. When you have to solve a problem, you have the domain of that problem. If that problem is wide, you divide it into smaller subproblems, which are problems too. So a subdomain is the domain of a subproblem.
    • Bounded Context (BC). It belongs to the solution space. Here you do have classes or whatever else artifacts of a programming language. If you have a problem, a BC is the application that implements and solves that problem. You model the domain of the problem, so that you have a domain model. Ideally the BCs relates 1:1 with subdomains.

    Whether a BC is just a class or a lot of them it will depend on the granularity when you split the domains into subdomains, and how you model the subdomains. There isn't any rule about how many classes a BC should have.

    Hope my explanation helps.