Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Design Patterns (GoF and modern) Module 11

Choosing patterns in design reviews and LLD rounds interview questions

Interview questions on choosing patterns in design reviews and LLD rounds: warm-ups, then what each harder question tests and how a good answer starts.

10 questions: 2 warm-ups and 8 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    How do you decide which design pattern to use for a requirement?

    Answered in the lesson Choosing a pattern: a problem-first map

  2. Fresher to mid

    What is a characterization test, and why write one before refactoring?

    A characterization test records what code does today, whatever anyone intended, and fails when that changes. You run the code on a set of inputs, bad ones included, and turn its current outputs and errors into the expected results. Before a refactoring it is the safety net: a refactoring must not change behaviour, and these tests show at once when a step did, while the step is still small enough to undo. They differ from tests written from a specification, which say what the code should do. If today's behaviour looks like a bug, keep the test as it is during the refactoring, and fix the bug afterwards as a separate change with its own test.

    From the lesson Refactoring katas with characterization tests

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to senior

    A parking lot charges by the hour on weekdays, a flat fee at weekends, and an extra fee at spots with an electric-vehicle charger. Which patterns would you use for pricing, and which alternative would you reject?

    What it tests
    Mapping the variations in a requirement to patterns, combining rules without a class per combination, and naming what was rejected and why.
    First step
    List what varies and who decides it: the base rule depends on when the car is parked, the extra fee on the spot, and both apply to one ticket. Then compare a Strategy for the base rule plus a list of surcharges with one price function full of conditions.
    Follow-ups

    From the lesson Choosing a pattern: a problem-first map

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    In a design review you proposed Observer for order-status notifications. A colleague says a direct call from the order service to the notification service is simpler. How do you decide who is right?

    What it tests
    Judging a pattern by the variation it protects, and weighing what Observer costs against a direct call.
    First step
    Count the dependents and how they change: one dependent that never changes favours the direct call; several, or dependents that other teams add, favour Observer. Then list what Observer would add: notification order, a failing subscriber and unsubscribing.
    Follow-ups

    From the lesson Choosing a pattern: a problem-first map

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    A 600-line function switches on the order type in five places, and a new order type ships next week. How do you refactor it safely, and in what order?

    What it tests
    Planning a refactoring toward Strategy in safe steps, with characterization tests first, and sequencing it against a deadline.
    First step
    Pin today's behaviour first: run the function on orders of every type, invalid ones included, and record its outputs and errors as characterization tests. Only then add one class per type beside the old code.
    Follow-ups

    From the lesson Refactoring katas with characterization tests

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  4. Senior to staff

    You must refactor legacy code that has no tests and reads the current time and a database directly. How do you start?

    What it tests
    Getting legacy code under test safely: finding seams, writing characterization tests through them, and keeping the first changes small.
    First step
    Do not touch the logic yet. Find the seams: put the clock and the database behind small parameters or functions whose defaults keep today's behaviour, so tests can replace them. Then write characterization tests through those seams.
    Follow-ups

    From the lesson Refactoring katas with characterization tests

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  5. Mid to senior

    How would you check automatically that a refactoring reached its goal, such as "no more switches on the order's status", and what can go wrong with such a check?

    What it tests
    Turning a design goal into a structural check, keeping it neither too strict nor too loose, and knowing what it cannot prove.
    First step
    Write the goal as a property a parser can see: no comparison of the status with a status name in the order's code. Then try the check on the legacy code, which must fail it, and on a design you know is right, which must pass.
    Follow-ups

    From the lesson Refactoring katas with characterization tests

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  6. Fresher to mid

    Twenty-five minutes into a 45-minute low-level design round, you have a class diagram and no code. What do you cut, and what do you tell the interviewer?

    What it tests
    Managing time in a design round, choosing the smallest core worth coding, and keeping the interviewer informed while cutting scope.
    First step
    Say it out loud first: the design is enough to start, and you will code the core now. Then pick the one flow the prompt and its tests care most about, such as adding a shape and undoing it, and code only the classes it needs.
    Follow-ups

    From the lesson Timed LLD mock rounds focused on patterns

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  7. Mid to senior

    Design the core of a drawing editor with undo and redo. Which patterns do you use, and how much memory does the undo history need after 10,000 edits on a drawing of 2,000 shapes?

    What it tests
    Choosing between Command and Memento for undo with numbers, and keeping undo correct for deletes, redo and groups.
    First step
    Name the two ways to undo: store each action as a command that can reverse itself, or store a snapshot of the drawing after each action. Then estimate both for 10,000 edits on 2,000 shapes before you choose.
    Follow-ups

    From the lesson Timed LLD mock rounds focused on patterns

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  8. Senior to staff

    Your drawing editor's core is done when the interviewer adds that shapes can be grouped and ungrouped, and undo must work on groups. How does your design change, and how do you show that it absorbed the change?

    What it tests
    Absorbing a change request with Composite, keeping undo correct for groups, and giving evidence of extensibility instead of claiming it.
    First step
    Before touching the code, say what will change: a group that plays the shape role and holds shapes, plus commands to group and ungroup. Then check which existing classes must change, ideally none, and say that too.
    Follow-ups

    From the lesson Timed LLD mock rounds focused on patterns

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes

All Design Patterns (GoF and modern) interview questions · The Design Patterns (GoF and modern) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.