- Published on
Mastering component cohesion, 3 principles every developer should know 😎
- Authors
- Name
- Cédric RIBALTA

The 3 Component Cohesion Principles: Why and How to Apply Them 😎
In software development, component cohesion is crucial to building modular and maintainable systems. In "Clean Architecture", Robert Martin introduces three key principles to guide component design: the Reuse/Release Equivalence Principle (REP), the Common Closure Principle (CCP), and the Common Reuse Principle (CRP). If you want to improve the structure of your code, it’s essential to understand and apply these principles.
Let’s explore how each of these principles works and how they can make your architecture more robust and scalable.
1. The Reuse/Release Equivalence Principle (REP) 🚀
Release what you reuse
This principle is simple: a reusable component must be publishable and versioned. In other words, if you want a component to be reused across different projects, it needs to be stable and structured enough to be released, with clear versioning and well-defined interfaces. This allows other developers to adopt it without fearing unexpected changes that might break their code.
Why is it important? Imagine you reuse a piece of code that was never versioned. If you make changes to this component later, you risk breaking the projects that depend on it. By versioning and releasing a component, you ensure stability because other developers will know exactly which version to use and when.
Concrete example: You create a library to manage database connections. To make it useful for other projects, you need to release a stable version with clear interfaces to guarantee safe integration. With each update, you release a new version so users know they can adopt it with confidence.
2. The Common Closure Principle (CCP) 🔄
Group what changes together
The Common Closure Principle states that classes within the same component should change for the same reasons and at the same time. This means that to minimize modification risks, you should group classes that evolve in response to the same types of changes. This way, you can manage changes in a more controlled manner.
Why is it important? When modifying your code, you want to avoid touching multiple scattered components. If your classes are well-grouped, the changes are localized and don’t affect other parts of the system. This principle allows you to reduce the propagation of modifications.
Concrete example: In a billing system, several classes handle business rules related to invoice management. If tax laws change, you’ll need to modify these rules. By applying the CCP, you group these classes in the same module so that only one module is modified when these rules evolve. This limits the risk of unexpected changes propagating elsewhere in your application.
3. The Common Reuse Principle (CRP) 🔧
Only reuse what you need
The Common Reuse Principle states that classes in a component should be reused together. If you use one class from a component, all the other classes in that component should also be relevant to you. If not, the component is poorly designed, as you’re importing dependencies you don’t need.
Why is it important? This principle helps you avoid introducing unnecessary dependencies into your code. If you use a class from a component that also contains functionality you don’t need, you unnecessarily bloat your project, increasing the risk of maintenance issues.
Concrete example: You have a module that contains classes for both form validation and authentication management. If another project only needs form validation, it shouldn’t be forced to import authentication classes. It’s better to separate these two functionalities into distinct components, following the CRP.
How these three principles work together 💡
These three principles come together to ensure better component cohesion:
- REP ensures your components are reusable and reliable by versioning them properly.
- CCP ensures that classes that change for the same reasons are grouped together, minimizing unintended changes elsewhere.
- CRP ensures that you only depend on the classes you truly need, avoiding unnecessary dependencies.
By following these three principles, you create components that are more cohesive, easier to maintain and evolve, and most importantly, more reliable in the long term.
Conclusion 🏁
Adhering to the component cohesion principles — REP, CCP, and CRP — will help you design more modular, maintainable, and scalable software architectures. By applying them correctly, you’ll avoid the pitfalls of overloaded components that are difficult to update or introduce unnecessary dependencies.
The next time you create or modify a component, think about these principles. They’re not just abstract rules, but practical tools that will guide you toward a cleaner and more efficient architecture.