liveBook · Manning

Domain layer

As explained in Unit Testing Principles, Practices, and Patterns

The application layer that contains domain concepts, rules, and business logic independently of external communication and infrastructure responsibilities.

The domain layer is the center of an application: it contains the business logic and concepts that provide the application’s essential functionality and differentiation. It should remain focused on business rules rather than external communication or infrastructure responsibilities. section 5.3

A domain layer in hexagonal architecture follows three practical boundaries:

  • Separates business logic from application services, which coordinate domain work with databases, APIs, and other external systems. section 5.3
  • Keeps dependencies flowing inward: domain classes may depend on one another, but not on application-service classes. section 5.5
  • Receives external connections through interfaces maintained by application services rather than exposing direct access to the domain. section 5.5

Business rule versus orchestration

A User domain class normalizes a name when its Name property changes. A UserController retrieves the user, invokes that domain operation, and saves the result. Likewise, a CustomerController retrieves a customer and product, invokes Purchase, and sends a receipt only after a successful purchase. The controllers coordinate; the domain objects enforce business behavior.

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines responsibilities, dependency direction, and communication boundaries, then demonstrates them with domain and controller examples.
Examples
Uses User name normalization and Customer purchasing with inventory, repositories, and receipt delivery.
What you can do after
Evaluate architecture by separating business behavior from orchestration and external communication.
How it connects
Connects business logic with application services, hexagonal architecture, observable behavior, encapsulation, and mocks.

Also explained in

Compare how 3 books explain domain layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.