Encapsulation allows a class to enforce rules about its data. For instance, a `Cart` class can ensure that the total quantity of items never exceeds a limit by using private fields and public methods that validate and update the quantity.
Additional Notes
How does encapsulation aid in maintaining object invariants?