Couplers
Couplers are a code smell category that binds the objects together, preventing the ability to extract and utilize them in different contexts. This tight coupling hinders flexibility and modularity, forcing the objects to be treated as a single unit, without the option to selectively isolate and reuse individual components. In such cases, any attempt to separate the interdependent objects would require significant modifications to the codebase, making it difficult to achieve code reusability and maintainability.
There can be some overlap between "Couplers" and "Change Preventers". The main issue with Couplers is high coupling. Therefore, Couplers can also prevent changes by making it difficult to modify or extend code without impacting other parts of the system. For instance, code smells like "Shotgun Surgery" and "Parallel Inheritance Hierarchies" belong to the Change Preventers category, and they are commonly caused by high coupling as well.
Couplers primarily address the issue of dependencies and coupling between components, while Change Preventers are more concerned with code design and practices that make code hard to change or extend. The resolution for Couplers often involves decoupling components, using design patterns like Dependency Injection, and minimizing direct dependencies. On the other hand, addressing Change Preventers often requires refactoring code to adhere to principles like the Single Responsibility Principle (SRP) and Open/Closed Principle (OCP), or modularizing code for easier maintenance and extension.
In summary, Couplers and Change Preventers are both related to code maintainability and flexibility, but they focus on different aspects of code quality. Couplers primarily deal with dependencies and coupling, while Change Preventers address design and code structure issues that make code difficult to modify or extend.
Here are some smells that belong to this category.
Feature Envy
When a method relies on multiple properties or methods from another class.
Inappropriate Intimacy
When classes are overly interconnected, they share too much information with each other.
Message Chains
When code navigates a series of object interactions, it creates long, tightly coupled chains.
Middle Man
When a class only offers minimal value and mainly delegates most of its calls to another class.
Indecent Exposure
When a class or method exposes internal details to the public unnecessarily.