concept model in category design

appears as: models, model, model
Object Design Style Guide

This is an excerpt from Manning's book Object Design Style Guide.

Composition can be used with a service object, making part of its behavior configurable. It can also be used with other types of objects, like entities (sometimes known as models), where composition is used for related child elements. For example, an Order object that contains Line objects could use composition to establish the relationship between an order and its lines. In that case, a client might provide not a single Line object, but a collection (array) of Line objects.

In the previous section, we split the PurchaseOrder entity into write and read models. The write model still carries the old name, but we called the read model Purchase-OrderForStockReport. The extra qualification ForStockReport indicates that this object now serves a specific purpose. The object will be suitable for use in a very specific context, namely arranging the data to produce a useful stock report for the user. The proposed solution isn’t optimal yet, because the controller still needs to load all the PurchaseOrder entities and convert them to PurchaseOrderForStockReport instances by calling forStockReport() on them, as in the following listing. This means that the client still has access to the write model, even though our initial goal was to prevent that from happening.

8.4. Build read models from domain events

One disadvantage of creating the StockReport read model directly from the write model’s data is that the application will make the calculations again and again, every time a user requests a stock report. Although the SQL query won’t take too long to execute (until the table grows very large), in some cases it’ll be necessary to use another approach for creating read models.

Figure 8.1. The ReceiveItems service makes a change to the PurchaseOrder write model and then dispatches domain events to EventDispatcher to allow other services like UpdateStockReport to listen in on those changes.