212: Building High-Performing Teams and Fostering Innovation Requires Trust
Encapsulation in Ruby and how trust foster innovation and high-performance
Thank you for reading Snippets of Text. Snippets from media about tech, programming, parenting, and more. This is a preview of a post available exclusively to paying subscribers. You can get unlimited access to all articles by purchasing a subscription.
Unrelated: Encapsulation and Command-Query Separation in OOP
To better encapsulate an object, hide data access behind methods and limit external access to the object's internal state. Start each class definition with private methods to identify if the object is doing too much.
Commands return no value. Yet, they create a side-effect located in the same or different component. Queries return a value but do not change anything about the system. The difference between these two types of messages is the creation of side effects. In programming, command method calls do not return values, only side effects, and travel to the right. Query methods return values, putting the caller responsible for handling that value on the left. Queries go westward, and commands go eastward. A Query method allows access to data within an object, but the object must ensure consumers don't cause issues. The provider must enforce values between the Query method call and return.
Off Topic: Avoiding Coupling in Your Ruby Code
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. Encapsulation should remove the ability to add if statements, forcing us to use commands instead of queries.
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 easier to understand and change. In Ruby, query methods return data, while command methods trigger side effects and do not return anything.
The object that owns the data can decide what should be displayed and not how. A value object is intended to be queried, and only that you don't do anything else with it. It simplifies our parameters. East orientation decreases coupling and increases code clarity, cohesion, and flexibility. At least information leaks knowledge. It leaks responsibilities. Their queries encourage you to put code in the wrong place.
Commands encourage polymorphism. Eastern encode, and commands enforce encapsulation. 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. In Ruby, a practical way to enforce encapsulation is to always return "self" from every method that modifies the state. Objects should be owners of their data and responsible for disclosing methods to access that data.
Current Work: Building High-Performing Teams and Fostering Innovation Requires Trust
Trust is the confidence that your peers have good intentions and aren't out to harm you. Teams that trust one another are comfortable being vulnerable and can admit mistakes and weaknesses. Teams should practice exchanging feedback in structured environments. In these safe environments, they can identify strengths and weaknesses without repercussions. Your software will always have room for improvement, so trust your programmers' intuition to decide when to stop working on it. Please give them the space to work remotely or in a private office.
Thanks for looking at the free preview of Snippets of Text. Please consider subscribing to the paid version if you find my work helpful. This way, I can spend more time developing new ideas to share with you.
Keep reading with a 7-day free trial
Subscribe to Snippets of Text to keep reading this post and get 7 days of free access to the full post archives.


![Practical Object-Oriented Design: An Agile Primer Using Ruby by [Metz Sandi] Practical Object-Oriented Design: An Agile Primer Using Ruby by [Metz Sandi]](https://substackcdn.com/image/fetch/$s_!alXB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdffe8694-6ec3-455c-9361-fe003e1a9deb_382x500.jpeg)
![Brave New Work: Are You Ready to Reinvent Your Organization? by [Aaron Dignan] Brave New Work: Are You Ready to Reinvent Your Organization? by [Aaron Dignan]](https://substackcdn.com/image/fetch/$s_!mTaA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f265120-f6d8-4570-b05c-7d1f1016f82d_329x500.jpeg)