Smells Flashcards
Define Duplicated Code
Two code fragments look almost identical.
Define Long Method
A method contains too many lines of code. Generally, any method longer than ten lines should make you start asking questions.
Define Large class
A class contains many fields/methods/lines of code.
Define long parameter list
More than three or four parameters for a method.
define divergent change
You find yourself having to change many unrelated methods when you make changes to a class. For example, when adding a new product type you have to change the methods for finding, displaying, and ordering products.
define shotgun surgery
Making any modifications requires that you make many small changes to many different classes.
define feature envy
A method accesses the data of another class more than its own.
define data clumps
Sometimes different parts of the code contain identical groups of variables (such as parameters for connecting to a database). These clumps should be turned into their own classes.
define primitive obsession
Use of primitives instead of small objects for simple tasks (such as currency, ranges, special strings for phone numbers, etc.)
Use of constants for coding information (such as a constant USER_ADMIN_ROLE = 1 for referring to users with administrator rights.)
Use of string constants as field names for use in data arrays.
define switch statements
You have a complex switch operator or sequence of if statements.
Fowler: using switch statements on type of object when you should be using subclasses/polymorphism
define lazy class
Understanding and maintaining classes always costs time and money. So if a class doesn’t do enough to earn your attention, it should be deleted.
define speculative generality
There’s an unused class, method, field or parameter.
define message chains
In code you see a series of calls resembling $a->b()->c()->d()
define middle man
If a class performs only one action, delegating work to another class, why does it exist at all?
define inappropriate intimacy
One class uses the internal fields and methods of another class.