- Refactoring
- Smells: coupling
Smells: coupling
Code smells in pieces that know too much about each other: feature envy, inappropriate intimacy, message chains, and how to decouple them.
5 guides32 min in totalRefactoring
The guides, in order
Read them top to bottom: each one builds on the ones before. The ones you've read carry a check.
- Feature Envy: when a method lives in the wrong classFeature Envy is a code smell where a method reads and computes mostly on another object's data, signalling that the logic belongs next to that data.6 min readStart here
- Inappropriate Intimacy: Classes That Know Too Much About Each OtherHow to spot two classes that read and write each other's internal fields, why it breaks code quietly, and the refactorings that restore clean boundaries.7 min read
- Message ChainsMessage chains force a caller to walk a path like a.getB().getC().getD(), so any change to that object graph breaks code far away.6 min read
- Middle ManA Middle Man is a class whose methods mostly forward calls to another object, adding a layer of indirection with no behaviour of its own.7 min read
- Global Mutable StateHow to recognise shared mutable state that any module can change, why it breaks tests and concurrency, and how to refactor it into explicit dependencies.6 min read
About this group
- What you'll find
- Feature envy, inappropriate intimacy, message chains, middle man and global mutable state.
- It's for you if…
- you can't change one class without breaking another and want to explain why in a code review.
- How each guide works
- Smell guides cover the signs, an example, why it happens, the treatment with its refactorings, what you gain and when it's not worth fixing. Technique guides show the problem, the code before and after, the steps, which smells it removes, its benefits and its cautions.
More groups in Refactoring
- Smells: bloatCode smells in code that has grown so much it can no longer be understood at a glance.See the 5 guides
- Smells: rigidityCode smells where one change forces many others, far away: divergent change, shotgun surgery, and the refactorings that cure them.See the 3 guides
- Smells: dead weightCode smells in code that adds nothing: duplicated, unused or speculative.See the 6 guides
- Smells: misused abstractionsCode smells where inheritance, types or conditionals are used against the grain.See the 4 guides
- Techniques: composing functionsRefactorings that split long functions into named pieces, or undo pieces that add nothing.See the 7 guides
- Techniques: organizing dataRefactorings that give data a name, a type and a single purpose: replace primitives and magic numbers, encapsulate fields and collections.See the 5 guides
- Techniques: simplifying callsRefactorings that make a function's signature say what it does and make it easy to use correctly.See the 4 guides
- Techniques: simplifying conditionalsRefactorings that make conditional logic readable at a glance: guard clauses, decomposed conditions and polymorphism instead of switches.See the 5 guides
- Techniques: moving featuresRefactorings that move each responsibility to the class or module where it belongs.See the 5 guides