Reducing Domain Ambiguity Through Encapsulation
Encapsulation should remove the ability to add if statements, forcing us to use commands instead of queries.
It’s important to avoid asking objects for information and perform a function for them. Instead, we should command objects to do what they need to do. Each object handles its part of the domain and should tell the next object what to do.
Ruby can be ambiguous when defining concepts and methods.
To reduce ambiguity, each object should handle a single concept and own its data and business logic. This makes their behavior more straightforward to understand and change.
The object that owns the data can decide what should be displayed and not how.
Commands encourage polymorphism. They push responsibility down into objects. It is a loosening coupling. If you’re returning `self` and hiding information about an object so you cannot query it, there’s no other option.
Encapsulation refers to grouping data with the methods that manipulate that data.
Encapsulation conceals an object’s information, represented by its data or internal state. This is important because coupling increases when objects access each other’s internal data.
Objects should be owners of their data and responsible for disclosing methods to access that data.