Bloaters Long Method
Large Class
Bloaters are code, methods and classes
that have increased to such gargantuan A method contains too many lines of
A class contains many
proportions that they’re hard to work with. code. Generally, any method longer
fields/methods/lines of code.
Usually these smells don’t crop up right than ten lines should make you start
away, rather they accumulate over time asking questions.
Primitive Obsession
as the program evolves (and especially
when nobody makes an effort to Long Parameter List
eradicate them). ■ Use of primitives instead of small
objects for simple tasks (such as
More than three or four parameters for currency, ranges, special strings
a method. for phone numbers, etc.)
■ Use of constants for coding
Data Clumps information (such as a constant
USER_ADMIN_ROLE = 1 for
referring to users with
Sometimes different parts of the code administrator rights.)
contain identical groups of variables ■ Use of string constants as field
(such as parameters for connecting to a names for use in data arrays.
database). These clumps should be
turned into their own classes.
Object-Orientation Switch Statements Temporary Field
Abusers
You have a complex switch operator Temporary fields get their values (and
All these smells are incomplete or or sequence of if statements. thus are needed by objects) only under
incorrect application of object-oriented certain circumstances. Outside of these
programming principles. circumstances, they’re empty.
Refused Bequest
If a subclass uses only some of the Alternative Classes with Different
methods and properties inherited from Interfaces
its parents, the hierarchy is off-kilter.
The unneeded methods may simply go
unused or be redefined and give off Two classes perform identical functions
exceptions. but have different method names.
Shotgun Surgery
Change Preventers Divergent Change
These smells mean that if you need to
You find yourself having to change Making any modifications requires that
change something in one place in your
many unrelated methods when you you make many small changes to many
code, you have to make many changes in
make changes to a class. For example, different classes.
other places too. Program development
becomes much more complicated and when adding a new product type you
expensive as a result. have to change the methods for finding,
displaying, and ordering products.
Parallel Inheritance Hierarchies
Whenever you create a subclass for a
class, you find yourself needing to
create a subclass for another class.
Couplers Feature Envy Inappropriate Intimacy
All the smells in this group contribute to
excessive coupling between classes or A method accesses the data of another One class uses the internal fields and
show what happens if coupling is object more than its own data. methods of another class.
replaced by excessive delegation.
Middle Man Message Chains
If a class performs only one action, In code you see a series of calls
delegating work to another class, why resembling $a->b()->c()->d()
does it exist at all?
Comments Duplicate Code
Dispensables
A dispensable is something pointless and
A method is filled with explanatory Two code fragments look almost
unneeded whose absence would make
comments. identical.
the code cleaner, more efficient and
easier to understand.
Data Class
Lazy Class
A data class refers to a class that
contains only fields and crude methods Understanding and maintaining classes
for accessing them (getters and always costs time and money. So if a
setters). These are simply containers class doesn’t do enough to earn your
for data used by other classes. These attention, it should be deleted.
classes don’t contain any additional
functionality and can’t independently Dead Code
operate on the data that they own.
A variable, parameter, field, method or
Speculative Generality
class is no longer used (usually
because it’s obsolete).
There’s an unused class, method, field
or parameter.
Other Smells
Below are the smells which don’t fall into
any broad category.
Incomplete Library Class
Sooner or later, libraries stop meeting
user needs. The only solution to the
problem—changing the library—is often
impossible since the library is
read-only.