Search code examples
javadomain-driven-design

DDD, Is domain model a domain or a sub-domain


These terms make me confuse, please help me understand it a little bit more. So what exactly is a Domain in DDD. So my understanding is, Domain is an entity or a class in my code and I start asking myself what is the sub-domain then? I want to give an example of an e-commerce system. Here's how I define each term.

// My understanding is, this class is a domain. 
// So domain model is actually a domain living inside of e-commerce bounded context.

package io.joseph.e-commerce.domain;

class ShoppingCart {
  private String shoppingCartId;
}

but yeah I think I miss understanding something since I don't know what is the sub-domain here.


Solution

  • Every software program relates to some activity or interest of its user. That subject area to which the user applies the program is the domain of the software. Some domains involve the physical world: The domain of an airline-booking program involves real people getting on real aircraft. Some domains are intangible: The domain of an accounting program is money and finance. Software domains usually have little to do with computers, though there are exceptions: The domain of a source-code control system is software development itself. -- Eric Evans, Domain Driven Design, 2004

    So the domain is the thing that your program is about - the problem that you are trying to solve (ex: Cargo Shipping).

    A domain model is not a particular diagram; it is the idea that the diagram is intended to convey. It is not just the knowledge in a domain expert's head; it is a rigorously organized and selective abstraction of that knowledge.

    The code is our attempt to describe to the machine how to manipulate information and messages the same way that our "rigorously organized and selective abstraction" would.

    The realization of a domain model in code is a likely to involve a lot of classes (not just one); and there are likely to be a lot of classes that aren't part of the domain at all (ex: I/O; message parsing; logging/monitoring/observability, and so on).