โ† 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 ensures a class has only one instance and provides a global access point?

    Answer: Singleton

    The Singleton pattern restricts instantiation of a class to one object and provides a static method to access it.

  2. In the Composite pattern, what role does the 'Leaf' class play?

    Answer: It is a primitive object with no children

    A Leaf represents a basic element with no children, implementing the component interface directly.

  3. Which design pattern converts the interface of a class into another interface that clients expect?

    Answer: Adapter

    The Adapter pattern wraps an existing class to make its interface compatible with another interface.

  4. What problem does the Chain of Responsibility pattern solve?

    Answer: Passing a request along a chain of handlers without knowing which will handle it

    Chain of Responsibility lets handlers decide whether to process a request or pass it to the next handler in the chain.

  5. In C++, the 'std::function' combined with lambdas is most closely associated with which pattern?

    Answer: Strategy

    The Strategy pattern defines a family of algorithms that can be swapped at runtime, matching how std::function holds interchangeable callables.

  6. Which pattern separates an abstraction from its implementation so both can vary independently?

    Answer: Bridge

    The Bridge pattern decouples abstraction and implementation by placing them in separate class hierarchies linked by composition.

  7. The Template Method pattern relies primarily on which C++ mechanism?

    Answer: Virtual functions and inheritance

    Template Method defines a skeleton algorithm in a base class using virtual functions that subclasses override to fill in steps.