refactoring

refactoring - Refactoring 1 cs2340: Refactoring and...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Refactoring 1 cs2340: Refactoring and Smalltalk Refactoring 2 Motivation Most of us will not be involved in a totally new forward-engineered product. There is already a code base or design. What if it is crummy? Refactoring 3 Refactoring Improving the design of code already written (and working!!). Used in many Agile development processes A disciplined technique not hacking Proper implementation requires good unit tests. Refactoring 4 Bad Smells Duplicate Code (Extract method/Introduce Superclass) Long Method (Extract method) OO methods (especially in Smalltalk) are short (5-10 lines) Large Class (Extract Class) Usually indicates violation of Single Responsibility (Low Cohesion) Refactoring 5 Bad Smells Long Parameter List (Introduce Parameter Object) from: 1 to: 4 with: [ ] except: [ ] ascending: true security: myAcl target: myClass Divergent Change (Extract Class) Shotgun Surgery (Move Method) Refactoring 6 Bad Smells Feature Envy (Extract Method, Move Method) Data Clumps (Extract Class, Preserve Whole Object, Introduce Parameter Object) Primitive Obsession (Replace Data Value with Object) Refactoring 7 Bad Smells Switch statements (Replace Type Code with State/Strategy, Replace conditional with Polymorphism) Lazy Class (Collapse Hierarchy, Inline Class) Speculative Generality (Collapse Hierarchy, Inline class, Remove Parameter) Refactoring 8 Bad Smells Conditional Field (Extract Class, Introduce Null Object) Message Chains (Hide Delegate, Extract Method, Move Method) Middle Man (Remove Middle Man, Inline method) Inappropriate Intimacy (Move Method, Move Field, Change bi to uni assoc) Refactoring 9 Bad Smell Alternative Classes with Different Interfaces (Rename Method, Move Method) Incomplete Library Class (Introduce Foreign Method, Introduce Local Extension) Data Class (Encapsulate Collection, Hide Method, Remove Setting Method) Refactoring 10 Bad Smell Refused Bequest (Push Down Method, Replace Inheritance with Delegation) Comments (Extract Method, Rename Method, Introduce Assertion) Refactoring 11 Video Store Example Movie Rental Customer children : int = 3 regular:int = 1 newRelease: int = 2 title : string priceCode : int daysRented:int name : string statement() : string * Refactoring 12 What about this design? Refactoring 13 Refactoring Step 1: Make Unit Tests Step 2: Start to look for Bad Smells Step 3: Apply 1 refactoring to correct Bad Smell Step 4: Modify Unit Tests Step 5: Run Tests to ensure nothing is broken Return to Step 2. Refactoring 14 Code statement | totalAmount freqRenterPoints result thisAmount newline tab|...
View Full Document

Page1 / 26

refactoring - Refactoring 1 cs2340: Refactoring and...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online