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
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.
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.
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.
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.
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.
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.
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.