Base CS from zero
Abstraction: multiple-choice review
Six questions that cut across the whole unit. Each one is a judgement call a working programmer makes — not a definition to recite, but the line between what an abstraction promises and what it actually hides.
Confirm you can connect the four ideas the unit built toward — interface vs implementation, encapsulation in a bundle, the module boundary and namespacing, and the leaky-abstraction tradeoff — and apply them to code you have never seen before.
A team rewrites the body of add(a, b) to compute the sum a faster way. The name, the two inputs, and the returned sum all stay the same. How many of the hundreds of call sites must change, and why?
A counter object bundles a data field count with methods increment() and value(). What does encapsulation actually buy you here?
A module defines six names and marks two of them as exports. Outside code tries to call one of the four unexported names directly. What happens, and why was the boundary worth enforcing?
A large program needs two functions both sensibly called format — one for dates, one for currency. Why does putting each in its own module stop them from colliding?
A function-call abstraction works fine for thousands of ordinary calls, then a runaway recursion crashes with a stack-overflow error that names stack frames. How should you read this through the unit?
Because every non-trivial abstraction leaks, a colleague concludes you should stop learning the layers underneath the ones you work in. What is wrong with that conclusion?
The unit’s through-line is one chain: an abstraction is a fixed interface over a hidden, replaceable implementation; a bundle applies that to data plus its operations and calls the hiding encapsulation; a module applies it to a whole group of code, with an enforced boundary and namespacing so private detail stays untouchable and short names stop colliding; and stacking these layers is how you manage complexity. The price is the leak — every non-trivial abstraction surfaces the layer below when that layer fails or runs slow, which is why you use the interface for the reasoning it buys and still learn the machinery underneath.