Bad Smells in
Code
CocoDojo
Duplicated Code
Extract out the common bits into theirown method
(extract method) if code is in same class if two classes
...
Long Method
extract method!
Large Class
Class trying to do too much often shows up
as too many instance variables.
Long Parameter
List
replace parameter with method (receiver explicitly asks
sender for data via sender getter method)
Exam...
Divergent Change
If you have a fixed class that does distinctly different things
consider separating out the varying code ...
Shotgun Surgery
The smell: a change in one class repeatedly requires little
changes in a bunch of other classes. try to mo...
Feature Envy
Method in one class uses lots of pieces from another
class. move method to move it to the other class.
Data Clumps
Data that's always hanging with each other (e.g. name
street zip). Extract out a class (extract class) for the...
Primitive
Obsession
Switch Statements
Use inheritance and polymorphism instead
(example of this was in Fowler Chapter 1; this is one of
the mo...
Lazy Class
Speculative
Generality
Temporary Field
Message Chains
Upcoming SlideShare
Loading in …5
×

Bad smells in code

909 views

Published on

Bad smells in code, coding, dojo, refactor

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
909
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Bad smells in code

  1. 1. Bad Smells in Code CocoDojo
  2. 2. Duplicated Code Extract out the common bits into theirown method (extract method) if code is in same class if two classes duplicate code, consider extract class to create a new class to hold the shared functionality.
  3. 3. Long Method extract method!
  4. 4. Large Class Class trying to do too much often shows up as too many instance variables.
  5. 5. Long Parameter List replace parameter with method (receiver explicitly asks sender for data via sender getter method) Example: day month, year, hour minute second ==> date
  6. 6. Divergent Change If you have a fixed class that does distinctly different things consider separating out the varying code into varying classes (extract class) that either subclassor are contained by the non-varying class.
  7. 7. Shotgun Surgery The smell: a change in one class repeatedly requires little changes in a bunch of other classes. try to move method and move field to get all the bits into one class since they areobviously highly dependent.
  8. 8. Feature Envy Method in one class uses lots of pieces from another class. move method to move it to the other class.
  9. 9. Data Clumps Data that's always hanging with each other (e.g. name street zip). Extract out a class (extract class) for the data. Will help trim argument lists too since name street zip now passed as one address object.
  10. 10. Primitive Obsession
  11. 11. Switch Statements Use inheritance and polymorphism instead (example of this was in Fowler Chapter 1; this is one of the more difficult refactorings)
  12. 12. Lazy Class
  13. 13. Speculative Generality
  14. 14. Temporary Field
  15. 15. Message Chains

×