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 1

Why patterns, and when not to use them interview questions

Interview questions on why patterns, and when not to use them: warm-ups, then what each harder question tests and how a good answer starts.

15 questions: 5 warm-ups and 10 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What are the four essential parts of a design pattern?

    Answered in the lesson What a design pattern is (and is not)

  2. Fresher

    What is the difference between aggregation and composition in a UML class diagram?

    Answered in the lesson Reading UML class and sequence diagrams

  3. Fresher

    What does "favour composition over inheritance" mean in practice?

    Answered in the lesson The design principles behind the patterns

  4. Fresher

    Why do some design patterns disappear in languages with first-class functions?

    Answered in the lesson How language features reshape patterns

  5. Fresher

    What is YAGNI, and how does it apply to design patterns?

    Answered in the lesson When patterns hurt: cost, YAGNI and overuse

Questions with model answers

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

  1. Mid to senior

    A teammate proposes "using more design patterns" to make a hard-to-change codebase easier to maintain. How do you respond, and what do you ask for instead?

    What it tests
    Treating patterns as answers to specific forces rather than as goals, and turning a vague request into named variations with costs.
    First step
    Ask which changes have been painful. List the last few changes that touched many files or broke something unexpected: a pattern is justified by a variation that keeps recurring, so the change history, not the catalogue, says where a pattern would pay.
    Follow-ups

    From the lesson What a design pattern is (and is not)

    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

    Is MVC a design pattern or an architecture style? Defend your answer, and say why the difference matters when a team discusses a design.

    What it tests
    Telling the levels of design apart, knowing how MVC combines smaller patterns, and using the level to scope a design discussion.
    First step
    Say that the name is used at two scales. Inside one user-interface component, MVC is a combination of smaller patterns: the views observe the model, views nest, and a controller decides how a view responds to input. As the layout of a whole web application, it is an architecture style.
    Follow-ups

    From the lesson What a design pattern is (and is not)

    Model answer, Pro.

    In the answer:

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

    A design document draws every relationship between its classes as a plain line. What do you ask before writing code from it, and which answers change the code?

    What it tests
    Reading relationships as decisions about ownership, lifetime and direction, and turning a vague diagram into concrete questions with code consequences.
    First step
    For each line ask three questions: who creates the object at the other end, whether it outlives this one, and which side calls the other. Those answers choose between composition, aggregation and a plain association, and the direction of the arrow, and each choice changes a constructor or a field.
    Follow-ups

    From the lesson Reading UML class and sequence diagrams

    Model answer, Pro.

    In the answer:

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

    A class diagram shows composition, a filled diamond, from Customer to Order. Is that right? What would the code and the data have to do if it were?

    What it tests
    Applying the strict meaning of composition, spotting a modelling error, and knowing which business rules would make the diagram right.
    First step
    Composition means an order belongs to exactly one customer and is deleted with that customer. Ask whether orders must survive the customer's account being closed. Invoices and tax records usually must, so a plain association with a multiplicity is the honest model.
    Follow-ups

    From the lesson Reading UML class and sequence diagrams

    Model answer, Pro.

    In the answer:

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

    java.util.Stack extends Vector. What goes wrong with that design, how would you build a stack instead, and when is extending a library's base class the right choice?

    What it tests
    Spotting inheritance used only to reuse code, the invariants it leaves unprotected, and the difference between a class designed for extension and one that is not.
    First step
    List what a Stack inherits from Vector: methods that insert, remove or read at any index. Each one lets a caller break the last-in, first-out rule, and none can be removed, because a Stack must still work wherever a Vector is expected.
    Follow-ups

    From the lesson The design principles behind the patterns

    Model answer, Pro.

    In the answer:

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

    Java's List.copyOf returns a list whose add() throws UnsupportedOperationException. Does that break the Liskov substitution principle? Defend your answer, and say what you would do in an API of your own.

    What it tests
    Reading a contract precisely, telling a documented optional operation from a broken promise, and designing types that make capabilities visible.
    First step
    Read the contract, not only the method name. The Collection interface documents add as an optional operation that may throw UnsupportedOperationException, so a list that refuses it keeps the promise as written. Then ask what that contract costs the callers who rely on it.
    Follow-ups

    From the lesson The design principles behind the patterns

    Model answer, Pro.

    In the answer:

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

    A Python service has a Java-style PricingStrategy hierarchy of eight classes. Four take constructor settings such as a rate or a cap, and the strategy is chosen by name from a config file at start-up. Plan the refactor: what replaces each class, and how do you migrate safely?

    What it tests
    Choosing between functions, closures, partial application and small classes for configured behaviour, keeping selection from configuration safe, and migrating step by step.
    First step
    Sort the classes by what they carry. The four without settings are functions. The four with settings need their values bound somewhere: a closure, functools.partial or a small frozen dataclass with __call__. Then decide how a name in the config file becomes one of them.
    Follow-ups

    From the lesson How language features reshape patterns

    Model answer, Pro.

    In the answer:

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

    A Java team keeps forty visitors over a twelve-class syntax tree, and plugins written by other teams add new node types. Would you replace the visitors with sealed interfaces and pattern-matching switch? Explain what you gain and what breaks.

    What it tests
    Seeing when a closed set of cases is an assumption you cannot make, comparing exhaustive matching with double dispatch, and designing a hierarchy that is closed in part.
    First step
    Start from the plugins. A sealed interface lists every permitted subtype, and they must live in the same module or package, so plugin node types cannot be permitted. That rules out sealing the whole tree; ask which part of it is really closed.
    Follow-ups

    From the lesson How language features reshape patterns

    Model answer, Pro.

    In the answer:

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

    A pull request adds a PaymentProviderFactory with one product and a PaymentProvider interface with one implementation, "for the future". How do you respond, and when would you accept it?

    What it tests
    Judging speculative generality with evidence, keeping the discussion constructive, and naming the conditions that justify a seam.
    First step
    Ask what the second provider is and when it arrives, and whether the tests need a fake provider today. If the answer to both is no, suggest calling the one provider directly behind a small function, and adding the interface when a second provider is real.
    Follow-ups

    From the lesson When patterns hurt: cost, YAGNI and overuse

    Model answer, Pro.

    In the answer:

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

    In a low-level design round, the interviewer asks why your design uses no pattern for sending notifications. How do you defend the choice, and what would make you add one?

    What it tests
    Defending simplicity with a named variation and a plan, instead of adding patterns to look thorough.
    First step
    State the variation you looked for and did not find: there is one channel today. Then say what would change your mind, such as a second channel or a choice per user, and how you would refactor: extract a channel interface and pass the channel in.
    Follow-ups

    From the lesson When patterns hurt: cost, YAGNI and overuse

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 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.