When creating the complex ecosystem that is an application, it’s important to set the correct boundaries and avoid tangling dependencies. To keep data apart from behavior, encapsulation protects attributes inside an object, exposing only messages. You decide which methods are declared as public for other people to consume based on your objects’ requirements, and which methods are private and kept from everyone else.
A good system depends on effective communication between objects, not just consistent data. In this lesson, you’ll learn the principle of encapsulation and how to use it in your Ruby classes.