Encapsulation hides internal state behind a controlled interface, preventing casual access and establishing a code contract. A consistent interface protects clients from representation changes, while a poorly designed interface can still invalidate state. section 3.2.4
The need becomes especially clear with mutable state in concurrent code: concentrating changes inside an object limits the impact of later fixes, although encapsulation alone cannot prevent every unwanted mutation. section 3.2.4
Hiding an abstract value representation
A functional module can keep Value’s constructors private while exposing smart constructors such as boolValue, stringValue, and intValue. Clients depend on the interface rather than pattern-matching over BoolValue, IntValue, FloatValue, or StringValue, so representation changes remain localized. section 3.2.4













