
Encapsulation does not make details mysterious. It specifies how the outside world may interact with a system. Internal state is protected, and external actions must pass through a limited, stable interface. An internal implementation can then change without forcing every user to change with it, while a faulty input is more likely to be contained at the boundary.
An espresso machine’s buttons let a user choose functions without directly altering the state of its heater or pump. A technician can still open the machine, so encapsulation does not mean that information is permanently invisible. Different roles simply have different points of access.
Encapsulation is close to abstraction, but they are not identical. Abstraction decides which details can be ignored in a discussion; encapsulation decides which details cannot be manipulated freely. Nor does encapsulation mean isolation: interfaces still connect systems. Good encapsulation makes dependencies explicit so that a change remains, as far as possible, within the part where it belongs.
Discover more from Geoffrey Chen
Subscribe to get the latest posts sent to your email.