By restricting direct access and defining controlled modifications.
Encapsulation allows a class to hide its internal data and provide methods to interact with it. This ensures that the object is used correctly and maintains valid states. In an e-commerce app, a `Product` class might encapsulate its `price` field, allowing changes only through a method that checks if the discount is valid.
Additional Notes
How does encapsulation enforce safe object design?