Skip to content

How to approach a case study

Difficulty: Intermediate

Key concepts

  • case study
  • delivery framework
  • time boxes
  • clarifying questions
  • assumptions
  • traceability
  • interview communication
  • expectations by level
  • What a case study on this site is, and what it is not.
  • How every study is laid out, so you know where to find the requirements, the design, the code, the tests, and the changes.
  • How to read a study so that you learn to design, not just to recognise a finished design.
  • How to run the five steps of the delivery framework in 45 minutes: what to spend time on, what to cut when time runs short, and what never to cut.
  • How to explain a design out loud, handle hints and pushback, and what is usually expected at junior, mid-level, and senior level.

Each case study starts from a short, vague request, such as “design a parking lot”, and ends with a design that is justified, written in C++, compiled, and tested. In between, it shows the decisions: which questions were asked, which answers were assumed, which designs were considered and why the simpler one usually won, and what happened when the requirements changed.

A study is one good answer, not the answer. Different answers to the clarifying questions lead to different designs, and the studies say so where it matters. If your design differs, the useful question is whether yours follows from your requirements, not whether it matches.

A study is also not a production system. It leaves out what a real product needs and a design exercise does not: storage that survives a restart, security, monitoring, deployment, and much of the error handling. Each study has a section listing what it leaves out. External services, such as payment providers, banks, email, and text messages, are always replaced by small stand-ins behind an interface, so the design can be tested without them. A study that handles money says plainly that it is not a financial system.

Every study follows the same order, which is the delivery framework with each step written out in full:

Framework step What the study contains
1. Requirements The original request. Clarifying questions with example answers. Scope and exclusions, with each assumption labelled as confirmed or assumed. Requirements, use cases, acceptance criteria, and invariants, each with an ID.
2. Entities and relationships An entity sketch: the things in the problem and who owns or uses whom.
3. Class design Tables that justify each class’s data members and member functions from the requirements, with the owner of each member; class outlines; the architecture and any patterns, each with the alternatives that were rejected.
4. Implementation C++ built in small steps, each of which compiles and is tested; traces of the main scenarios; state diagrams where an object has states; a runnable demo and its real output; tests for boundaries, failures, and invariants.
5. Extensibility Concurrency and storage, only where the problem needs them; changed requirements and how the design absorbs them.
Afterwards How to present the design in an interview; production limitations; a traceability table from each requirement to the design, the code, and the tests.

Requirements and checks carry short IDs so that later sections can point back to them:

  • FR-1, FR-2, … are functional requirements: what the program must do.
  • NFR-1, … are non-functional requirements: how well, how fast, or under what limits.
  • UC-1, … are use cases: one actor reaching one goal.
  • AC-1.1, AC-1.2, … are acceptance criteria for use case 1: checkable statements that become tests.
  • INV-1, … are invariants: facts that must be true whenever no operation is in progress, such as “a spot holds at most one vehicle”.

Assumptions are labelled confirmed, when the study’s example answers settle them, or assumed, when the study chose a reasonable default that a real customer might change. An assumed item is a place to look when you try a different answer.

Each study ends with a table that links every requirement to what implements it and what checks it, in the form taught on the page on traceability, with a column added for the code. A row looks like this; the names here show the format and are not taken from a study:

Requirement Design element Code Tests Status
FR-1 a ticket is issued on entry Gate creates a Ticket Gate::admit ac_1_1_entry_issues_a_ticket Tested
NFR-1 an answer within 1 second none: the work is small and in memory n/a none: checked by measuring Not measured

Read it forwards to find requirements with no test, and backwards to find code that no requirement asks for. Both are findings, and the studies report them rather than hide them.

The code for a study lives under examples/case-studies/, in one folder per study, with one folder per step: step-1, step-2, and so on. Each step compiles on its own with GCC and Clang, with warnings treated as errors, and is tested. The page shows the parts of each step that matter, taken from those files, so the code on the page cannot drift from the files. To see a whole step, open its folder.

There are three ways to use a study, and the first is the one that teaches the most.

  1. Try it first, then compare. Read the request and the clarifying questions. Stop before the answers, write your own answers, and design for them: a requirements list, an entity sketch, the main classes. Then read on and compare. Where the study differs, find the requirement or the answer that caused the difference. Twenty minutes of your own attempt makes the study’s choices mean something.
  2. Read it top to bottom. Useful the first time you meet a kind of problem, such as the first study with a state machine. Read the rejected alternatives as carefully as the chosen design: they are where the reasoning is.
  3. Use it to rehearse. Read only the request, set a timer for 45 minutes, and work through the five steps out loud, as in an interview. Then read the study’s section on presenting the design, and compare what you covered.

Whichever way you read, keep asking the questions the studies answer: which requirement made this class necessary, what would change if an answer were different, and which test would fail if this line were wrong.

The studies are listed in the sidebar in order of their IDs. Each one names its prerequisites at the top; the earlier sections cover them. If you are short of time, a reasonable start is the Connect Four study, which is small and walks through the delivery framework end to end, then Parking lot or Library management. After those, choose by what you want to practise:

To practise Studies
Modeling, ownership, and simple rules Connect Four, Parking lot, Library management, Parcel locker
State machines Vending machine, ATM workflow, Elevator system
Policies that vary, without forcing patterns Parking lot (fee rules), Cache with eviction policies, Expense sharing, Elevator system (dispatching)
Money and rounding Shopping cart and checkout, Expense sharing
Components, interfaces, and stubbed services Logging framework, Notification service, ATM workflow
Concurrency Task scheduler, Booking and ticket reservation, Inventory, Logging framework (background writing)
Recursive structures and larger models In-memory file system, Chess

The studies are being written one at a time; each appears in the sidebar once it is published, and until then its name here is plain text. When you have finished a study, the extension challenges give one more change to try on it, with hints and evaluation criteria.

On a project, each step of the framework can take days. In an interview, the same steps fit into about 45 minutes, and a common risk is not that you design badly but that you run out of time with the important parts missing. A rough plan, consistent with the times on the page on the delivery framework:

A 45-minute session as five time boxes; check the clock at each arrow
Text description of the diagram

Six boxes in a row, joined by arrows. 1 Requirements, about 5 minutes: questions, a numbered list, and an out-of-scope list. 2 Entities, 3 to 5 minutes: a sketch of what owns and uses what. 3 Class design, 10 to 15 minutes: data members, member functions, and an invariant for each important class. 4 Implementation, 10 to 15 minutes: the core functions and one traced scenario. 5 Extensibility, about 5 minutes: one or two changes. Then questions, with whatever time remains.

Diagram source (Mermaid)
flowchart LR
R["1 Requirements<br/>about 5 min<br/>questions, numbered list,<br/>out of scope"] --> E["2 Entities<br/>3 to 5 min<br/>sketch: owns, uses"]
E -->  C["3 Class design<br/>10 to 15 min<br/>members, functions,<br/>an invariant for each<br/>important class"]
C --> I["4 Implementation<br/>10 to 15 min<br/>core functions,<br/>one traced scenario"]
I --> X["5 Extensibility<br/>about 5 min<br/>one or two changes"]
X --> Q["Questions<br/>what remains"]

The times are a guide, not a rule. Some interviewers want more code, some want more discussion; if they say so, follow them. What matters is that you decide where the time goes, rather than finding at minute 40 that you are still on the second class.

  • The clarifying questions. Two or three questions with a stated default for each take two minutes and shape the design. A design built on unstated assumptions cannot be judged, even if it is good.
  • The out-of-scope list. It protects your time. “Payments are out of scope; I will put them behind an interface with a stand-in, and show what happens when it refuses” is a design decision, said in one sentence.
  • Who owns what. In C++ an object’s lifetime is part of its design. Say which objects hold which by value, which by std::unique_ptr, and which only refer to others, and what keeps the referred-to objects alive.
  • One invariant per important class, and one traced scenario. A trace through the code is how you, and the interviewer, find out whether the design works.
  • Minor classes: name them and say what they hold, without writing them.
  • Boilerplate: getters, constructors that only copy their arguments, and #include lines can be skipped or waved at.
  • Most tests: name the tests you would write, especially for the edges and the failures, and write one.
  • Alternatives: mention one rejected alternative for the biggest decision and why; the rest can wait for questions.

A design that is not explained is hard to judge, however good it is. These habits make your reasoning visible.

  • Say what you are about to do. “First I will pin down the requirements, then sketch the main objects, then design the classes and write the core of the code.” The interviewer can then follow, or redirect you early.
  • Ask questions with a default. “Can a vehicle use a bigger spot than it needs? If you have no preference, I will assume yes, but only when no spot of its size is free.” A question with a default keeps you moving, and it shows that you know the question matters.
  • Write things down. A numbered requirements list and an out-of-scope list, kept visible, let both of you point at them later: “this covers FR-3”.
  • Give each class one sentence. “A Spot knows its size and which ticket holds it; it does not know prices.” If you cannot say it in one sentence, the class may be doing too much.
  • Justify, then move on. For each decision, one reason from the requirements is enough: “a std::vector of spots, because FR-2 hands them out in number order and no spot is added while the car park is open”. Save the long comparison for a question.
  • Trace a scenario, then a failure. Walk through one use case in the code, then one that goes wrong: a full car park, a payment that fails, a request for a seat that someone else just took.
  • Invite the change. Near the end, name a likely change and show where it lands: “if we add electric charging, a spot gains a charger and a ticket gains a charge; the fee rules do not change”.

An interviewer’s question is often a hint. “What happens if two drivers arrive at the last spot at the same time?” usually means “your design has not thought about this yet”. The useful response is to take the question seriously, think it through out loud, and change the design if it needs changing. Defending a design against a good point costs more than admitting the gap. Equally, if you made a choice for a stated reason, it is fine to keep it: “I chose a single thread because FR-2 says one gate, so requests arrive one at a time; if several gates were served by separate threads, I would make finding a free spot and taking it one step under a lock.”

What interviewers look for differs by level. The table below is this site’s judgement of common practice, not a standard; companies differ, and so do interviewers.

Level Usually expected
Junior Asks some clarifying questions; finds the main classes; gives each class clear data and member functions; writes correct code for the core operation; traces one scenario. Hints are expected and fine.
Mid-level Drives the requirements without prompting; names the invariants and protects them; makes ownership explicit; handles the main failure cases; uses a pattern only where it removes a real problem; tests the edges.
Senior All of the above, faster; weighs alternatives and explains the trade-offs; anticipates changes and shows where they land; asks about concurrency, storage, and scale, and adds them only when the answers call for them; says what is out of scope and why.

At every level, what counts against a candidate is much the same: coding before the requirements are clear, a class for every noun, patterns added to show that you know them, long silences, and a design whose objects have no clear owner.

  • Starting with classes. A class list written in the first minute is a guess. The requirements, even five lines of them, come first.
  • Modeling everything. A parking lot does not need a Building, a Floor, a Wall, and a Paint class. Model what the requirements use; mention the rest as out of scope.
  • Patterns first. “I will use the Strategy pattern” is not a design. “Fees vary by car park and change each year, so the fee rule is an object or function the car park is given” is, and it may or may not need the pattern.
  • Concurrency and storage nobody asked for. Adding threads, a database, or a message queue to a problem that needs none of them uses your time and adds risk. Ask, and add them only if the answer calls for them.
  • No failure cases. A design that only works when everything goes right has not been tested. Every study has a section on what goes wrong; so should your answer.
  • Treating a study as the answer to memorise. Interviewers change one requirement to see whether you can follow it through. Learn why each decision was made, so you can make it differently when the requirement is different.
  • A case study here is one justified, compiled, and tested design for a vague request: one good answer, not the answer, and not a production system.
  • Every study follows the delivery framework in full: requirements with IDs and labelled assumptions, entities, class design with justifications, incremental C++ with tests, changes, presentation, limitations, and a traceability table.
  • Learn the most by trying each problem first and comparing; use the rest of the studies to rehearse under a timer.
  • In 45 minutes, protect the clarifying questions, the out-of-scope list, ownership, an invariant per class, and one traced scenario; cut minor classes, boilerplate, and most tests.
  • Explain as you go: say what you will do, ask questions with defaults, justify each decision from a requirement, trace a failure, and treat questions as hints.