Design an inventory management system
medium 80 minCount goods in several places, promise them to orders without ever promising too much, ship or let go, and explain every count.
Watch lesson4:28
UML design
The classes and their arrows
The point: all arrows point away from the coordinator, and only one class can change a count.
The design to reach: one coordinator, one guarded line, plain records
1/7Start from the verbs
Goods arrive, are promised, leave, or the promise ends. Four verbs on one coordinator, Inventory. Callers see nothing else.
implementsusesowns (dies together)
Read it
Arrows that people mix up
| From, to | Relation | Why this one |
|---|---|---|
| Inventory, StockLine | Owns | Nobody else has a reference. A line outside the lock could be changed unseen |
| Inventory, PickPolicy | Uses | Handed in. It may be shared, and it has no state worth guarding |
| Reservation, Pick | Owns | A pick means nothing without its promise |
| Pick, StockLine | No arrow | It holds the names and not the line. A pick in a log must not let anyone change stock |
| Policy, StockLine | Reads a list | It receives lines for one call and answers with picks. C++ can say so with const |
The same
As a text diagram for the whiteboard
Should the reservation give itself back?
Breaksreservation.cancel() changes the lines
- How
- The promise has references to its lines and calls them.
- Limit
- The lines change outside the inventory lock, and the caller can cancel twice from two threads.
- Choose when
- Never, with threads.
WorksThe reservation calls the inventory
- How
reservation.cancel()callsinventory.release(self.id).- Limit
- Two objects that know each other, for a shorter line at the caller.
- Choose when
- When callers hold reservations for a long time and like methods on them.
StrongThe inventory ends promises by id
- How
inventory.release(id)- Limit
- Callers must keep a number.
- Choose when
- The default: one door, one lock, and an id survives a restart.