Which statement best describes abstraction?
Users work with a simplified interface; the implementation can change behind it.
Abstraction · Exercise 1 of 4
Twenty multiple-choice questions on abstraction in C++: interface vs implementation, abstraction vs encapsulation, abstract data types, interfaces, templates, pimpl and RAII. Pick an option to check your answer instantly.
Which statement best describes abstraction?
Users work with a simplified interface; the implementation can change behind it.
Which pairing is correct?
Encapsulation is the mechanism that enforces the abstraction.
What defines an abstract data type such as a stack?
A stack is "push, pop, top, empty with LIFO behaviour" whether it uses an array or a linked list.
C++ has no interface keyword. How is an interface usually expressed?
Concepts are the compile-time counterpart for templates.
Which of these does not provide abstraction in C++?
Public data exposes the representation, the opposite of hiding it.
A ReportService takes a Storage& (abstract) instead of a MySqlStorage&. What is the main benefit?
That is the dependency-inversion principle and the basis of unit testing with mocks.
What is the main purpose of the pimpl idiom?
It also keeps heavy #includes out of the header and gives a stable binary interface.
A class holds std::unique_ptr<Impl> with Impl only declared in the header. Where must its destructor be defined?
unique_ptr's deleter needs the complete Impl type; defaulting the destructor in the header would compile it where Impl is incomplete.
What does RAII hide from the user of a class like std::lock_guard or std::ifstream?
Release happens on normal exit, early return and exceptions alike.
What is a "leaky abstraction"?
Example: an interface that works only if functions are called in an undocumented order.
Timed online tests with instant scores and explanations.