Chapter 8. Domain model

 

This chapter covers

  • Designing domain models
  • Exploring a real-world domain model
  • Understanding entities and value objects
  • Thinking about persistence

In chapter 2 we explored the M in MVC—the presentation model our controllers beam through a prism of markup, refracted onto the screen by the view. For the most part, the presentation model doesn’t contain any behavior. Its power is in its shape and structure, not in its algorithms and interactions. The presentation model serves the user interface.

Deeper, toward the application’s core, there’s another focus: the logic and code that do the work. The core also contains the valuable calculations and business rules that make the application worth using. In an ecommerce application, this focus might be on orders and products, and in a hotel management system the focus might be on reservations and rooms. This other focus—we’ll call it the application’s domain—deserves a model too: the domain model.

In this chapter, we’ll explore a sample model for a simple system that manages a small ecommerce business. The model enables the application to provide an interesting service. Without the model, the application provides no value. We place great importance on creating a rich model that clearly expresses the business reality and the solution to problems in that domain.

8.1. Understanding the basics of domain-driven design

8.2. A sample domain model

8.3. Summary