Lesson 3 of 8 · 2 min 19 sec

A Module for Every Branch

Chapters

  1. Two ways to hold many things
  2. Opening and closing
  3. How others refer to a branch
Transcript
Download transcript

Two ways to hold many things

The library has many members and many branches. Members are rows in one table. Branches are different. Each branch is a module of its own, with its own sealed shelf. Why the difference? Branches owns a keyed set of child modules. One key per branch, one Shelf module per key. It is declared in the version file, beside the data, as children. And it names the exact version of Shelf it holds. Remember that. It matters when Shelf changes. Here is the difference. Members can read every one of its rows. Branches cannot read inside a shelf. It can only attach one, remove one, and call its public functions. A branch is opened and closed as a whole. It holds a table of its own. That is what earns it a module.

Opening and closing

An admin opens branch five. Branches creates a new, empty Shelf and attaches it on key five, in the same call. Then a tool is added to it. Later, branch five closes. Branches asks the shelf one question: is every tool home? It is. Branches removes the attachment. The shelf and everything inside it are gone when the call ends. Open branch five again. The key is the same. The module is new. It starts empty. Nothing of the old shelf comes back. Now someone tries to close branch three. Its shelf answers: no, tools are out. Branches refuses and changes nothing. Removing a module removes its memory, so the rule that guards it belongs in the design.

How others refer to a branch

One more consequence. The loan book remembers which branch a tool came from. It stores the branch number. It cannot store the shelf itself, or a handle to it. To reach a shelf, code asks Branches by number. And because every key is a whole module, the app sets a limit. Here, thirty-two branches.