This document discusses code smells, which are signs that may indicate deeper problems in software code. It defines code smells and provides examples, such as duplicated code, long methods, and large classes. The document categorizes different code smells as couplers, change preventers, bloaters, dispensables, and abusers. It advocates refactoring code when smells are detected, comparing code maintenance to gardening work where optimizations remove unnecessary growths.
4. “We have looked at lots of code, written for projects
that span the gamut from wildly successful to nearly
dead. In doing so, we have learned to look for certain
structures in the code that suggest—sometimes,
scream for—the possibility of refactoring.” (Martin
Fowler, Kent Beck)
“Are warning signs about potential problems in code.
Not all smells indicate a problem, but most are
worthy of a look and a decision.” (William C. Wake)
DEFINIÇÃO
5. LITERATURA
2000 - “The Pragmatic Programmer:
From Journeyman to Master”
“Rather than construction, software is more like
gardening—it is more organic than concrete.
You plant many things in a garden according to
an initial plan and conditions. Some thrive,
others are destined to end up as compost. […]
You constantly monitor the health of the garden,
and make adjustments (to the soil, the plants, the
layout) as needed.”
6. LITERATURA
2000 - “Refactoring: Improving the Design of
Existing Code”
2003 - “Refactoring Workbook”
2005 - “Refactoring to Patterns”
7. LITERATURA
2006 - “A Subjective Evaluation of Software
Evolvability Using Code Smells: An Empirical Study”
2018 - “Refactoring: Improving the Design of
Existing Code 2nd Edition)”
8. Duplicated Code
Long Method
Large Class
Long Parameter List
Divergent Change
Shotgun Surgery
Feature Envy
Data Clumps
Primitive Obsession
Switch Statements
Parallel Inheritance
Hierarchies
CODE SMELLS
Lazy Class
Speculative Generality
Temporary Field
Message Chains
Middle Man
Inappropriate Intimacy
Alternative Classes with
Different Interfaces
Incomplete Library Class
Data Class
Refused Bequest
Comments
9. Duplicated Code
Long Method
Large Class
Long Parameter List
Divergent Change
Shotgun Surgery
Feature Envy
Data Clumps
Primitive Obsession
Switch Statements
Parallel Inheritance
Hierarchies
CODE SMELLS
Lazy Class
Speculative Generality
Temporary Field
Message Chains
Middle Man
Inappropriate Intimacy
Alternative Classes with
Different Interfaces
Incomplete Library Class
Data Class
Refused Bequest
DIVIDE ET
IMPERA
10. Duplicated Code
Long Method
Large Class
Long Parameter List
Divergent Change
Shotgun Surgery
Data Clumps
Primitive Obsession
Switch Statements
Parallel Inheritance
Hierarchies
CODE SMELLS
Lazy Class
Speculative Generality
Temporary Field
Alternative Classes with
Different Interfaces
Incomplete Library Class
Data Class
Refused Bequest
DIVIDE ET
IMPERA
Feature Envy
Message Chains
Middle Man
Inappropriate Intimacy
11. Duplicated Code
Long Method
Large Class
Long Parameter List
Data Clumps
Primitive Obsession
Switch Statements
CODE SMELLS
Lazy Class
Speculative Generality
Temporary Field
Alternative Classes with
Different Interfaces
Incomplete Library Class
Data Class
Refused Bequest
DIVIDE ET
IMPERA
Feature Envy
Message Chains
Middle Man
Inappropriate Intimacy
Divergent Change
Shotgun Surgery
Parallel Inheritance
Hierarchies
12. Duplicated Code
Switch Statements
CODE SMELLS
Lazy Class
Speculative Generality
Temporary Field
Alternative Classes with
Different Interfaces
Incomplete Library Class
Data Class
Refused Bequest
DIVIDE ET
IMPERA
Feature Envy
Message Chains
Middle Man
Inappropriate Intimacy
Divergent Change
Shotgun Surgery
Parallel Inheritance
Hierarchies
Long Method
Large Class
Long Parameter List
Data Clumps
Primitive Obsession
13. Switch Statements
CODE SMELLS
Temporary Field
Alternative Classes with
Different Interfaces
Incomplete Library Class
Refused Bequest
DIVIDE ET
IMPERA
Feature Envy
Message Chains
Middle Man
Inappropriate Intimacy
Divergent Change
Shotgun Surgery
Parallel Inheritance
Hierarchies
Long Method
Large Class
Long Parameter List
Data Clumps
Primitive Obsession
Duplicated Code Lazy Class
Speculative Generality
Data Class
14. CODE SMELLS
Incomplete Library Class
DIVIDE ET
IMPERA
Feature Envy
Message Chains
Middle Man
Inappropriate Intimacy
Divergent Change
Shotgun Surgery
Parallel Inheritance
Hierarchies
Long Method
Large Class
Long Parameter List
Data Clumps
Primitive Obsession
Duplicated Code Lazy Class
Speculative Generality
Data Class
Switch Statements
Temporary Field
Alternative Classes with
Different Interfaces
Refused Bequest
16. Change Preventers
“Violate the rule which says that
classes and possible changes should
have a one-to-one relationship”
● Divergent Change
● Shotgun Surgery
● Parallel Inheritance Hierarchies
17. Bloaters
“Something that has grown so large
that it cannot be effectively handled”
● Data Clumps
● Primitive Obsession
● Long Method
● Large Class
● Long Parameters List
18. Dispensables
“They all represent something unnecessary
that should be removed from the source
code”
● Duplicated Code
● Lazy Class
● Speculative Generality
● Data Class
● Comments
19. Abusers
“Cases where the solution does not
fully exploit the possibilities of OOP”
● Switch Statements
● Temporary Field
● Alternative Classes with Different Interfaces
● Refused Bequest
20. Conclusão
“The gardening metaphor is much closer to the realities of
software development. Perhaps a certain routine has
grown too large, or is trying to accomplish too much—it
needs to be split into two. Things that don't work out as
planned need to be weeded or pruned.”
To be continued…
… Refactoring Techniques