210: How to Use Value Objects to Improve the Design of Your Ruby Code
Thoughts on value objects and modular code in Ruby
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: How to Improve the Modularity of Your Ruby Code
To achieve a particular business process, some objects outline the necessary steps. Factories create the values that domain objects need. It is crucial to centralize the creation of a valid default state so each component can access the correct objects to do its tasks.
The objects define the role that different implementations can play. Loosely coupled classes are not bound together. It is possible to substitute across the boundary of whoever plays the role. This is done by reducing the dependencies in each object. An object that needs little to no test setup is considered context-independent. These objects are not linked to other application parts and can be used in various scenarios.
Off Topic: How to Use Value Objects to Improve the Design of Your Ruby Code
Value Objects are immutable data structures that cannot be changed. Although Ruby's core library does not enforce immutability, it is essential to represent the use cases of an application. We should move towards that ideal. Value Objects are global and language-agnostic, and each language has its way of implementing them. `Struct` bases equality on attributes rather than object identity.
Thanks for taking a look 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_!0EIg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F316730b2-b333-4805-bc27-b74e1b67eddb_382x500.jpeg)