Show Menu
Cheatography

CPSC501 Cheat Sheet by

Bloaters

Long Method
Too many lines of code.
1, [Replace Temp with Query, 3, 4], [Replace Method with Method Object], [Decompose Condit­­ional, 1]
Large Class
Class contains many fields­/me­tho­ds/­lines of code.
2, Extract Subclass, Extract Interface, Duplicate Observed Data
Primitive Obsession
Use of constants for coding inform­ation. Use of primitives instead of small objects for simple tasks.
Replace Data Value with Object, [ 3 or 4], [Replace Type Code with Class, Subclasses or State], Replace Array with Object
Long Parameter List
More than three or four parameters for a method.
Replace Parameter with Method Call, 4, 3
Data Clumps
Different parts of the code contain identical groups of variables
2, 3, 4. 1. Extract Method 2. Extract Class 3. Introduce Parameter Object 4. Preserve Whole Object

Refact­oring Benefits

- Improves code organi­zation.
- Reduces code duplic­ation.
- Simplifies support.
- Can improve organi­zation of code.
- Easier mainte­nance.
- Code becomes more flexible
- Better Code Readab­ility
 

Object­-Or­ien­tation Abusers

Altern­ative Classes with Different Interfaces
2 classes perform identical functions but have different method names.
Rename Methods, [Move method, Add Parameter, Parame­terize Method], Extract Superclass
Refused Bequest
Subclass uses only some of the methods and property
Replace Inheri­tance with Delega­tion, Extract Superclass
Switch Statements
Complex switch operator
Replace Condit­ional with Polymo­rphism, Ex
Temporary Field
Get their values only under certain circum­stances
Extract class, Replace Method with Method Object
Incorrect applic­ation of object­-or­iented progra­mming princi­ples.

Change Preventers

Divergent Change
Change many unrelated methods when you make changes to a class.
Parallel Inheri­tance Hierar­chies
Whenever you create a subclass for a class, you find yourself needing to create a subclass for another class.
Shotgun Surgery
Making any modifi­cations requires that you make many small changes to many different classes.
Need to change something in one place in your code, you have to make many changes in other places too.
 

Dispen­sables

Comments
A method is filled with explan­atory comments.
Duplicate Code
Two code fragments look almost identical.
Data Class
Class that contains only fields and crude methods for accessing them. Don’t contain any additional functi­onality and can’t indepe­ndently operate on the data that they own.
Dead Code
A variable, parameter, field, method or class is no longer used
Lazy Class
Class doesn’t do enough to earn your attention,
Specul­ative Generality
There’s an unused class, method, field or parameter.
Something pointless and unneeded whose absence would make the code cleaner, more efficient and easier to unders­tand.

Couplers

Feature Envy
A method accesses the data of another object more than its own data.
Move, Extract Method
Inappr­opriate Intimacy
Uses the internal fields and methods of another class
[Move Method and Field], [Extract Class and Hide Delegate], [Replace Delegation with Inheri­tance]
Incomplete Library Class
 
[Introduce Foreign Method or Local Extension]
Message Chains
a->­b()­->c­()-­>d()
Hide Delegate, [Extract Method and Move Method]
Middle Man
Class only delegates work
Remove Middle Man
Excessive coupling between classes
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          More Cheat Sheets by Heavenel