Reading diagrams / Topic 16 of 42

Storage handed in or reached for

The rule

Where code gets its storage decides how easy it is to test and to change. Here are two versions of one allocation service. In the first, storage arrives as a record of functions handed in. In the second, each handler reaches for the real repository itself.

The structure lens shows the difference. “Records of functions” lists each port and the values that fill it. “Calls through a field of a record” says, for each call through such a record, whether the record was handed in or reached for.

A line traces a value back as far as the lens can follow it. So a line under handed in on every path can end in reaches for: the code that calls through the record is handed it, and further up, the code that built the record reached for the real thing. That is the point of handing it in: a test can build the record another way.

The allocation service from Architecture Patterns with Python, with storage handed in.

Loading the structure picture.

The same service with storage reached for.

Loading the structure picture.

Loading the worked examples and practice.