Part 3 of 8 · 2 min read
Shared and hidden models
Each context decides what it shows.
BM walks through a music shop, MusicCorp, with a warehouse and a finance department. Both are contexts. Each has a few things only it needs, and a few things it shows.
- The warehouse hides its pickers (people who pick orders) and its shelf locations.
- Finance hides its general ledger.
- Finance needs the stock level to value the company, so the stock item is a shared model.
Even the shared model is not shown in full. Inside the warehouse a stock item has a record of where it lives on the shelves. That detail is not exposed. So each shared thing has two forms: an internal one and an external one that the context chooses to publish.
Shared model and hidden model
A shared model is the part of a context's data that it publishes to others. A hidden model is everything else, which only the context itself may use.
Example: a stock item shows "title, quantity" to finance and keeps "aisle 4, shelf C" hidden.
The same word can mean different things in different contexts. BM's example is a return. For the customer context, a return is a shipping label, a parcel sent out and a refund awaited. For the warehouse, a return is a parcel about to arrive and an item to restock. The warehouse stores extra facts, such as a restock request, that mean nothing to the customer side. This is not a flaw. It is why the contexts must not share one class or table for "return".
A worked example (made up). A shop keeps one Customer table with 30 columns, used by billing, shipping and marketing. Billing adds a column for card tokens. Marketing adds a column for email consent. Shipping adds a column for delivery notes. Every change risks the other two teams, and any team can break the others by a bad migration. With three contexts, each owns a small customer record of its own: billing holds 8 columns, shipping 6 and marketing 7. Each publishes only what the others need, such as a customer id and a name. Duplication of the id and name is the price. Independence is what it buys.
BM adds a point about code. When a team first finds the contexts, it should keep them as modules inside one codebase, with shared and hidden models. These modules are then ready to become services when needed. This links to page 3 (the modular monolith) and page 8.
Check yourself: 1. Why does finance not see the shelf location of a stock item? 2. Give another word that could mean different things in two parts of a shop. 3. In the made-up example, what is duplicated and why is that acceptable?