AlgoViz

Design an inventory management system

medium 80 min

Count goods in several places, promise them to orders without ever promising too much, ship or let go, and explain every count.

Watch lesson4:28

Patterns

Used, refused, and why

The point: two patterns solve a problem that is really here. The others are named so that the interviewer hears why they are not.

Used

Patterns that earn their place

PatternWhereWhat it buys
StrategyPickPolicyNear first, cheapest, fewest parcels, without touching reserve
Observer, in its smallest formLowStockThe inventory does not know mail, chat or buying
Record of eventsMovementCounts can be explained and rebuilt
Dependency injectionPolicy, clock, listenerA test owns time

Refused

Patterns people add by habit

PatternWhy not
SingletonOne inventory at run time is one new in main. Two in a test must be possible
StateThree verbs, one open state. An enum and one check are shorter and complete
FactoryNothing to choose: one kind of line, one kind of promise
CommandA movement looks like one, but it is the past and cannot be executed
Inheritance of productsNo behaviour differs

Principles

SOLID, with one proof each

LetterProof in this code
SA change to the choice of place opens one file. A change to alerts opens another
OInOrder was added without editing Inventory
LEvery policy answers with a full plan or None. One that gave a part would break reserve
ILowStock has one method. A mailer does not have to implement ten
DInventory gets a clock and a policy. It creates neither

One policy for the place. What if rules are combined?

BreaksFlags
How
plan(qty, lines, near=True, cold=False)
Limit
Every new rule edits every caller.
Choose when
Never.
WorksSubclasses for combinations
How
NearAndColdFewest
Limit
Two rules with three values each are nine classes.
Choose when
Two combinations that never grow.
StrongFilter, then order
How
A filter removes places that may not send. An order sorts the rest. fill takes from the front.
Limit
Two small interfaces in place of one.
Choose when
As soon as a rule says must and another says rather.