22 terms

Refactoring - Code Smells

Bad Smells in Code. By Kent Beck and Martin Fowler
STUDY
PLAY
Duplicate Code
This "smell" appears in code when you see the same code structure in more than one place.
Long Method
A method that has too many things going on. Or the method name cannot fully describe all that is going on within the method.
Large Class
When a class is trying to do too much, it often shows up as having too many instance variables. When a class has too many instance variables, duplicated code cannot be far behind.
Long Parameter List
A method or class that has many parameters makes it harder to understand and more difficult to use.
Divergent Change
When you are not able to make a change in a single clear spot of the system. When more that one method or class is changed because of a single change in your business (ex. sales tax increase), or an external dependency change (ex. database change).
Shotgun Surgery
Similar to divergent change, but is the opposite. When one change in the code forces you to make many little changes to a lot of different classes.
Feature Envy
A method that seems more interested in a class other than the one it actually is in.
Data Clumps
The same fields in a couple of classes, parameter in the same method signatures. Bunches of data that hang around together really ought to be made into their own object.
Primitive Obsession
When code is reluctant to use small objects for small tasks, such as money classes that combine number and currency, ranges with an upper and lower, and special strings such as telephone number and zip code.
Switch Statements
This "smell" is fixed by using the OO notion of polymorphism.
Parellel Inheritance Hierarchies
This "smell" is a special case of shotgun surgery. In this case, every time you make a subclass of one class, you also have to make a subclass of another.
Lazy Class
A class that has been downsized with refactoring may no longer be performing enough tasks to be worth keeping.
Speculative Generality
When you are designing and implementing code to handle special cases that are not part of the original requirements for the project. Code that seems to get in the way and causes more confusion than what it is worth.
Temporary Field
When you see an object in which an instance variable is set only in certain circumstances. Such code is difficult to understand, because you expect an object to need all of its variables.
Message Chains
When a client asks one object for another object for another object, and so on.
Middle Man
If most of an object's methods are deligating tasks to other classes, the object will have this smell.
Inappropriate Intimacy
When you find two classes who's methods calling each other too frequently.
Alternative Classes with Different Interfaces
Classes that have different interfaces, but could be refactured to use the same interface.
Incomplete Library Class
Incomplete Library Class
Data Class
Class that only have fields and properties.
Refused Bequest
Child classes do not use all the inherited methods from the parent class.
Comments
When comments are necessary for explaining the code.
OTHER SETS BY THIS CREATOR