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
What is the main advantage of the Prototype pattern over direct object construction?
Answer: It copies an existing instance, useful when construction is costly or complex
Prototype clones an existing configured object, bypassing expensive initialization steps required when constructing from scratch.
In Hexagonal Architecture (Ports and Adapters), what is a 'Port'?
Answer: An interface defining how the application interacts with the outside world
A Port is an interface (inbound or outbound) that defines a contract between the application core and external actors.
Which SOLID principle does the Open/Closed Principle (OCP) describe?
Answer: Software entities should be open for extension but closed for modification
OCP states that you should be able to add new behavior by extending, not modifying, existing source code.
What distinguishes an Interpreter pattern use case from a Strategy pattern use case?
Answer: Interpreter deals with parsing and evaluating grammars; Strategy selects among algorithms at runtime
Interpreter defines a grammar for a language and interprets sentences, while Strategy encapsulates interchangeable algorithms unrelated to language parsing.
In the context of C++ design patterns, what problem does the 'Pimpl' (Pointer to Implementation) idiom solve?
Answer: It hides implementation details to reduce compilation dependencies and stabilize ABI
Pimpl moves private implementation details to a separate class accessed via a pointer, reducing header dependencies and compile times.
Which pattern is most appropriate when an object's behavior must change based on its internal state?
Answer: State
The State pattern allows an object to alter its behavior when its internal state changes, appearing to change its class.
In event sourcing architecture, how is application state reconstructed?
Answer: By replaying the sequence of stored immutable events from the event log
Event sourcing stores each state change as an immutable event; current state is derived by replaying all events in order from the log.