Focus On Behavior, Not State, for a More Maintainable Codebase - Shopify
Sep 1, 2022

Summary
This post details a shift in code design philosophy from focusing on state (what an object is) to behavior (what an object does) to improve maintainability. It introduces the concept of wrapping domain objects (like 'selling plans') into new classes that expose behavior-oriented methods, rather than directly accessing internal state or database details. This approach aims to reduce coupling, prevent the leakage of internal logic, and make the codebase more resilient to future feature additions like installments or layaway. The post also discusses the need for a translation layer (e.g., an extra table) to bridge the gap between internal domain logic and reporting requirements for data teams.
More from the Code Modularity and Boundary Enforcement trail
- A Packwerk Retrospective - Shopify
- Building a Business System Integration and Automation Platform at Shopify - Shopify
- Shopify-Made Patterns in Our Rails Apps - Shopify
- Remove Circular Dependencies by Using Dependency Injection and the Repository Pattern in Ruby - Shopify
- Adopting Sorbet at Scale - Shopify