Code Smells
Long Version
Here’s a detailed breakdown of all the code smells from the Refactoring Guru site:
1. Bloaters
- Long Method: Methods that grow too long.
- Large Class: Classes that contain too many responsibilities.
- Primitive Obsession: Using primitives instead of small objects for simple tasks.
- Long Parameter List: Too many parameters in a method.
- Data Clumps: Repeated data groups that should be objects.
2. Object-Orientation Abusers
- Switch Statements: Using conditionals instead of polymorphism.
- Temporary Field: Fields used only in some situations.
- Refused Bequest: Subclass ignoring inherited methods.
- Alternative Classes with Different Interfaces: Similar classes with different interfaces.
3. Change Preventers
- Divergent Change: Different changes are needed for one class for various reasons.
- Shotgun Surgery: A small change requires modifications in multiple places.
- Parallel Inheritance Hierarchies: Whenever a subclass is created, another parallel subclass is needed elsewhere.
4. Dispensables
- Duplicate Code: Code that is repeated in multiple places.
- Lazy Class: A class that is no longer useful or pulling its weight.
- Data Class: Classes that only have fields and getter/setter methods.
- Dead Code: Code that is never executed.
- Speculative Generality: Over-engineered design that isn't needed yet.
- Comments: Excessive commenting instead of improving code clarity.
5. Couplers
- Feature Envy: A method that uses data from another class more than its own.
- Inappropriate Intimacy: Two classes that are too closely tied.
- Message Chains: Chaining calls through multiple objects.
- Middle Man: A class doing too much delegation.
6. Others
- Incomplete Library Class: Using library classes but missing required methods.
- Data-Only Classes: Classes that hold data but lack behavior.
This table should help you quickly recall key types of code smells:
Category | Code Smells |
---|---|
Bloaters | Long Method, Large Class, Primitive Obsession, Long Parameter List, Data Clumps |
Object-Orientation Abusers | Switch Statements, Temporary Field, Refused Bequest, Alternative Classes with Different Interfaces |
Change Preventers | Divergent Change, Shotgun Surgery, Parallel Inheritance Hierarchies |
Dispensables | Duplicate Code, Lazy Class, Data Class, Dead Code, Speculative Generality, Comments |
Couplers | Feature Envy, Inappropriate Intimacy, Message Chains, Middle Man |
Others | Incomplete Library Class, Data-Only Classes |
TLDR; Version
This structure can make it easier to memorize. Each category has a mnemonic or common cause, such as "Bloaters" representing too much growth, "Object-Orientation Abusers" representing improper use of OOP, and so on.
Category | Code Smells | Mnemonic |
---|---|---|
Bloaters | Long Method, Large Class, Primitive Obsession, Long Parameter List, Data Clumps | Big Large Problems (BLP) |
Object-Orientation Abusers | Switch Statements, Temporary Field, Refused Bequest, Alternative Classes with Different Interfaces | Switched Things Required (STR) |
Change Preventers | Divergent Change, Shotgun Surgery, Parallel Inheritance Hierarchies | Difficult Changes (DC) |
Dispensables | Duplicate Code, Lazy Class, Data Class, Dead Code, Speculative Generality, Comments | Unnecessary Code Delete (UCD) |
Couplers | Feature Envy, Inappropriate Intimacy, Message Chains, Middle Man | Closely Tied Classes (CTC) |
Others | Incomplete Library Class, Data-Only Classes | Incomplete Design (ID) |
Every Bit of Support Helps!
If you have enjoyed this post, please consider buying me a coffee ☕ to help me keep writing!