Problem analyzer
medium 45 minEight questions that turn any prompt into a design skeleton in about six minutes: verbs, container, item, manager, policy, lifecycle, speed and sharing.
Video lesson · Chapter 1 of 6
Make a prediction
Eight questions for any prompt
1:00Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
A problem analyzer here is not a tool that thinks for you. It is a fixed list of questions, always asked in the same order, with one line written for each answer. The list makes sure that nothing important is forgotten while you are nervous.
The middle five have an old short name, C.I.M.P.L., which sounds like simple: Container, Item, Manager, Policy, Lifecycle. We put verbs in front, because a class without a call is decoration. We put speed and sharing behind, because they choose the containers and the locks.
The answers map to decisions. Policies with several forms suggest Strategy. Lifecycles suggest a table of moves or State. Speed picks the data structure. Sharing picks the lock. The mapping is a suggestion that each answer must earn.
Why it exists
The first six minutes decide the round. People who start drawing at once often forget one of two things: what varies, or what two users do at the same moment.
A repeatable list also frees your head. You do not think about what to think about. And the interviewer can follow, because you say the question aloud before you answer it.
Lists have a danger: filling them without thinking. That is why each line must end in a decision or in the words not needed here.
A short history
1935
After the crash of the Boeing Model 299, the prototype of the B-17, checklists became part of flying. It is the story most often told about their beginning.
1945
George Polya publishes How to Solve It: understand the problem, make a plan, carry it out, look back. A list of questions for mathematics.
1989
Kent Beck and Ward Cunningham present CRC cards at OOPSLA: one card for each class, with its responsibilities and collaborators.
1992
Ivar Jacobson and colleagues publish a method driven by use cases, with entity, interface and control objects. Start from what users do.
2008
The World Health Organization publishes a surgical safety checklist, used before an operation begins, before the cut, and before the patient leaves.
Words to know
- Verb
- A call from outside: park, lend, move a piece.
- Container
- What holds the things.
- Item
- A thing with an identity that is managed.
- Manager
- The object that receives verbs and keeps the rules between items.
- Policy
- A rule that may have several forms.
- Lifecycle
- The phases of one item and the allowed moves.
- Speed
- The call that must be fast, and how many items there are.
- Sharing
- What two callers could touch at the same time.
- Gap
- A question without an answer. Ask it, or state an assumption.
How it works
Step through the idea, or press Play.
Verbs. Who calls what?
Understand it
Start here
The toy doctor's checklist
Lee repairs toys. All toys are different, and the checklist on Lee's board is always the same. It has eight boxes.
The toys change, the list does not.
The list
Eight questions and what each decides
The analyzer
| Letter | Ask | Decides | If there is no answer |
|---|---|---|---|
| V verbs | Who calls, and what do they want? | Public methods | Stop and ask. Nothing works without it |
| C container | What holds the things? | Owner of the collection | One map inside the manager |
| I item | What has an identity and changes? | Entity classes | Perhaps it is only a value |
| M manager | Who keeps rules between items? | The class with the verbs | The container may be enough |
| P policy | Which rule has or will get several forms? | Strategy, function, or a table | Plain code |
| L lifecycle | Which phases, which moves, which are forbidden? | Table of moves, or State | No status field |
| S speed | Which call is hot, with how many items? | Data structure | A list, and say so |
| S sharing | What can two callers touch at once? | Lock, semaphore, queue, transaction | Single thread, said aloud |
The order, and where you go back
One picture for C.I.M.P.L.
Container
A box.
Item
The things in the box.
Manager
Somebody stands beside the box and takes requests.
Policy
The rule book in their hand. It can be exchanged.
Lifecycle
The conveyor belt that carries each thing from phase to phase.
Details of the first rows have their own pages: requirements, entities and owners, class design. How much time each part gets is in the execution flow.
Prompt 1
Parking lot
Design a parking lot
| Question | Answer | Decision |
|---|---|---|
| Verbs | enter, pay, leave | ParkingSystem with three methods, used by gates |
| Container | Lot, floors, spots | Lot owns spots. A floor is only a number unless it has rules |
| Item | Spot, ticket, vehicle | Ticket and spot have identity. Car and bike differ in size, so vehicle is a value |
| Manager | ParkingSystem behind entrance and exit gates | Gates are callers, not owners |
| Policy | Price: hourly, flat, weekend. Spot: nearest, random | Price is Strategy. Spot choice is a function |
| Lifecycle | Spot: free, taken, free. Ticket: issued, paid, left | Small tables of moves |
| Speed | Nearest free spot per size, ticket by number | Heap or bit set per size, map for tickets |
| Sharing | Two gates, one last spot | One lock around find and take. A semaphore alone does not say which spot |
Prompt 2
Elevator
Design an elevator system
| Question | Answer | Decision |
|---|---|---|
| Verbs | call from a floor, choose a floor, one step of time | Dispatcher and Car |
| Container | Building with cars. Shaft and floor are numbers | No class for a number |
| Item | Car, request. A button is an event | Request has floor and direction |
| Manager | Dispatcher picks the car, the car plans its stops | Two owners, two rules |
| Policy | Which car: nearest, least busy, by destination. Stop order: SCAN or LOOK | Strategy for the dispatcher |
| Lifecycle | Car: idle, up, down, doors open, out of service | State. Up to down goes through a stop, never directly |
| Speed | Next stop above or below | Two sorted sets of floors |
| Sharing | Buttons and the moving car change the stops | One worker per car, requests through a queue |
Lifecycle of a car
Prompt 3
LRU cache
Design an LRU cache
| Question | Answer | Decision |
|---|---|---|
| Verbs | get, put | Two methods, both must be O(1) |
| Container | The cache itself | A hash map is how, not what |
| Item | Entry with key and value | A node, private |
| Manager | None besides the cache | Do not invent a CacheService |
| Policy | Eviction: LRU, LFU, FIFO. Expiry by time | Strategy only if it may be exchanged. Expiry as Decorator |
| Lifecycle | Entry: present, evicted. Nothing more | No State. Cold, warm and full are words about the cache, not phases with rules |
| Speed | Lookup and move to front | Hash map plus doubly linked list |
| Sharing | get changes the order | One lock. A read-write lock does not help |
Prompt 4
Chess
Design a chess game
| Question | Answer | Decision |
|---|---|---|
| Verbs | move, resign, undo, show | Game is the door |
| Container | Board, 8 by 8 | 2D array. A square is a pair of numbers |
| Item | Piece: king, queen, rook, bishop, knight, pawn. Move | Pieces behave differently, so here subclasses are right |
| Manager | Game for turns, a rules object for check | A piece knows its steps. It does not know check |
| Policy | How a piece moves, how a computer scores | Polymorphic pieces. Scoring only if there is a computer player |
| Lifecycle | Setup, in progress, ended by mate, draw or resignation. Turn: white, black | Check is a fact about a position, not a phase |
| Speed | Piece on a square, last move | Array and a stack of moves for undo |
| Sharing | Two players take turns | Nothing until online play. Then one queue for matching |
Prompt 5
Vending machine
Design a vending machine
| Question | Answer | Decision |
|---|---|---|
| Verbs | insert, select, cancel, refill | Machine is the door |
| Container | Machine, slots with products | Map from code to slot |
| Item | Product, slot, sale | A coin is a value |
| Manager | The machine, with a payment part | Payment behind one method |
| Policy | Cash, card, phone. Refund rule | Strategy for payment |
| Lifecycle | Machine: idle, has money, dispensing. Sold out belongs to a slot, not to the machine | State, because select means something else in each |
| Speed | Product by code | Map. Sales in an append-only list |
| Sharing | Buttons, sensor and phone app | One event at a time |
Side by side
The same list, five shapes
Where each problem is heavy
| Problem | Heavy line | Light line | First class to write |
|---|---|---|---|
| Parking lot | Speed and sharing | Lifecycle | Spots |
| Elevator | Lifecycle and policy | Item | Car |
| LRU cache | Speed | Manager, lifecycle | The cache with its list |
| Chess | Policy: how pieces move | Sharing | Board and one piece |
| Vending machine | Lifecycle | Container | Machine and its states |
A line that helps
- Policy: price, three forms today, so a function per form
- Lifecycle: none, an entry is there or not
- Sharing: two gates, one last spot, lock around find and take
A line that fills space
- Policy: Strategy pattern
- Lifecycle: created, updated, deleted
- Sharing: thread safe
Keywords
A program that asks, instead of answering
A program can look for words in a prompt. But words answer nothing. A naive search even finds words inside words: one is in phone and add is in address. So our analyzer does two modest things: it turns whole words into questions, and it reports gaps in your own answers.
From a word to a decision
The analyzer in code
Substrings give patterns for words that are not there.
NAIVE = { "Singleton": ["single", "one", "global"], "Decorator": ["add", "wrap", "extend"],}def naive(prompt): text = prompt.lower() return [name for name, words in NAIVE.items() if any(w in text for w in words)]assert naive("Design a phone address book") == ["Singleton", "Decorator"]Line 9
w in text looks inside words. This is the bug, and it is a small copy of what people do when they hear one word and name a pattern.
A new prompt
The charging shelf: never seen before
The prompt: a library lends tablets from a shelf with 12 charging slots. A reader may have one tablet at a time. Hand out the fullest one. Tablets come back to any free slot. Broken ones are taken out. Try the eight lines yourself before you look.
Eight lines in six minutes
| Question | Answer | Decision |
|---|---|---|
| Verbs | lend, give back, report broken | Three methods |
| Container | Shelf with 12 slots | A slot is only a place: the shelf counts |
| Item | Tablet with number, battery and phase | One entity. Reader is an id |
| Manager | Desk | Keeps the rule of one per reader |
| Policy | Fullest now, least used was mentioned as an idea | A function parameter, no class |
| Lifecycle | charging, out, broken | Table of four moves |
| Speed | Fullest of 12, a few times an hour | A loop. Battery changes all the time, so a heap would be wrong as well |
| Sharing | Two librarians at two screens | One lock around the three methods |
Every noun a class
1/3Nouns from the prompt
Library, shelf, slot, tablet. A chain where each only returns the next.
owns (dies together)has (lives on)uses
From the eight lines
1/3Verbs on the desk
The three verbs become three methods of the manager.
owns (dies together)uses
Charging shelf, from the eight lines
The L line, written as data.
import threadingfrom dataclasses import dataclassMOVES = { ("charging", "lend"): "out", ("out", "give back"): "charging", ("charging", "break"): "broken", ("out", "break"): "broken",}@dataclassclass Tablet: number: int battery: int phase: str = "charging" def fire(self, event): if (self.phase, event) not in MOVES: raise ValueError(f"cannot {event} tablet {self.number}, it is {self.phase}") self.phase = MOVES[(self.phase, event)]Lines 4 to 9
Four moves from the eight lines. Broken has no way out, so it is the last phase.
The lend call
Quick drill
Two prompts in five words
Cover the right side and say C, I, M, P and L for both. Then add the verbs and the two S.
Library and food delivery
| Letter | Library management | Online food delivery |
|---|---|---|
| V | borrow, return, search | order, accept, pick up, deliver |
| C | Shelf and section: the catalogue | The restaurant's menu |
| I | Book copy, member, loan | Order, dish, courier |
| M | Librarian, better: lending desk | OrderService |
| P | Lending rules | Price, choice of courier |
| L | On shelf, borrowed, returned | Placed, accepted, picked up, delivered |
| S speed | Copy by number, title search | Open orders of a restaurant |
| S sharing | Last copy, two members | Two couriers, one order |
When the prompt gives you nothing
- 1
What holds the resources?
Start with one map from id to item.
- 2
What is handled?
The thing that would get a number on a paper form.
- 3
Who controls?
The desk where a person would ask.
- 4
What can vary?
Ask: which rule did you change last?
- 5
What phases?
Ask: how does one of these end?
- 6
Several threads?
Ask: who else can press a button now?
Summary
The whole topic in one minute.
Ask eight questions in order: verbs, container, item, manager, policy, lifecycle, speed, sharing. Write one line for each, ending in a decision or in not needed.
The answers give classes, the rule that varies, the table of moves, the containers and the lock. Keywords only tell you what to ask.
Look back at the end: every verb has an owner, every item has a first and a last phase, every shared thing has a guard.
- Verbs, container, item, manager, policy, lifecycle, speed, sharing.
- Every line ends in a decision or in not needed.
- Words in the prompt give questions, never patterns.
- One form of a rule is plain code.
- Check is a fact, not a phase. Sold out belongs to a slot.
- Find the heavy line and spend your time there.
- Look back: owners, first and last phase, guards.
Sources
- Beck and Cunningham: A Laboratory for Teaching Object-Oriented Thinking (CRC, 1989)
- WHO surgical safety checklist
- Checklist, history
- How to Solve It (book, 1945)
- Entity, control and boundary (Jacobson, 1992)
- Google SRE book: launch coordination checklist
- OWASP: threat modeling
- AWS Well-Architected
- Google: what to look for in a code review
- C4 model
- Architectural decision records