Challenging the Single-Responsibility Principle
This article provocatively challenges the conventional wisdom surrounding the Single-Responsibility Principle (SRP), arguing its common interpretation often leads to over-engineered 'distributed monoliths'. It introduces an alternative 'blood group law' for component classification, emphasizing code reusability and practical maintainability. This fresh perspective on a foundational software engineering concept offers a pragmatic approach to architecting systems, which is highly appealing to experienced developers on HN seeking efficient and elegant solutions.
The Lowdown
The author takes aim at the widely revered Single-Responsibility Principle (SRP), suggesting its rigid application often results in overly fragmented software systems rather than cohesive, maintainable ones. They argue that the SRP, while well-intentioned, can be misinterpreted to justify excessive code splitting, leading to architectural complexities like 'distributed monoliths' or 'spaghetti code' due to a lack of clear boundaries.
- The core of the author's alternative philosophy is the mantra: 'minimize code, maximize use cases,' which advocates for building highly reusable software components across an organization to reduce overall code footprint.
- To achieve this reusability, the article introduces Siedersleben's 'blood group law' (part of the 'Quasar architecture style'), a practical method for classifying software components.
- Group 0 (Generic components): These are entirely generic, devoid of technical or business logic, much like utility libraries (e.g., Lodash). They can be consumed by any other component without reducing the consumer's reusability.
- Group T (Technical components): These focus on technical concerns (e.g., configuration, ORMs). They have value outside the immediate project and are strong candidates for open-sourcing.
- Group A (Domain components): These encapsulate the core business logic. The goal is to continuously refactor and generalize logic from A components, moving it into Group 0 or T, ideally by adopting or creating open-source solutions.
- Group AT (Anti-pattern): This classification represents a technical (T) component that incorrectly depends on a domain-specific (A) component, a dependency structure that should be avoided.
By categorizing components in this manner, the author provides a concrete framework to guide architectural decisions, aiming to maximize the amount of generic (0) and technical (T) code, thereby fostering better reusability and a more maintainable codebase than a strict, potentially misapplied, SRP.