← All CPP Flashcard Decks

Design Patterns & Architecture Flashcards

7 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Design Patterns & Architecture flashcards as text
  1. Which pattern is best suited for implementing undo/redo functionality in an application?

    Answer: Command

    The Command pattern encapsulates operations as objects with execute/undo methods, making undo/redo straightforward.

  2. In the Flyweight pattern, what is the key distinction between intrinsic and extrinsic state?

    Answer: Intrinsic state is shared across instances; extrinsic state is context-specific

    Flyweight stores intrinsic (invariant) state internally and receives extrinsic (varying) state from the client at runtime.

  3. Which architectural pattern divides an application into Model, View, and Presenter components?

    Answer: MVP

    MVP (Model-View-Presenter) replaces the Controller with a Presenter that mediates between View and Model with no direct View-Model connection.

  4. What is the primary intent of the Null Object pattern?

    Answer: Represent missing objects with a no-op implementation to avoid null checks

    Null Object provides a default do-nothing implementation, eliminating the need for null checks scattered throughout client code.

  5. In the Visitor pattern, what is 'double dispatch' and why is it needed?

    Answer: Two virtual calls that resolve the concrete types of both the visitor and the element

    Double dispatch uses two polymorphic calls — one on the element to accept a visitor, and one on the visitor to act on the concrete element type.

  6. Which principle does the Dependency Inversion Principle (DIP) state?

    Answer: High-level modules should not depend on low-level modules; both should depend on abstractions

    DIP states that both high-level and low-level modules should depend on abstractions, reducing coupling between layers.

  7. Which pattern defines an object that encapsulates how a set of objects interact, promoting loose coupling?

    Answer: Mediator

    The Mediator pattern centralizes complex communications between objects, so they interact through the mediator rather than directly.