- Refactoring
- Smells: misused abstractions
Smells: misused abstractions
Code smells where inheritance, types or conditionals are used against the grain.
4 guides24 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.
- Repeated Switches: the same type-code switch scattered across a codebaseHow to spot the same switch on a type code repeated in several places, why it slows every change, and how to refactor it into polymorphism or data.6 min readStart here
- Refused Bequest: Subclasses That Reject What They InheritHow to spot subclasses that throw, no-op or zero out inherited methods, why it happens, and how to refactor toward honest hierarchies.6 min read
- Temporary Field: State That Only Lives During One Method CallHow to spot object fields that hold meaningful values only while one operation runs, why they cause bugs, and how to refactor them away.6 min read
- Flag ArgumentsHow to spot boolean parameters that switch a function between two behaviours, and how to split them into functions whose names say what they do.6 min read
About this group
- What you'll find
- Repeated switches, refused bequest, temporary fields and flag arguments.
- It's for you if…
- you see the same switch in several places or subclasses that override what they inherit.
- 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: couplingCode smells in pieces that know too much about each other: feature envy, inappropriate intimacy, message chains, and how to decouple them.See the 5 guides
- Smells: dead weightCode smells in code that adds nothing: duplicated, unused or speculative.See the 6 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