17
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting [email protected]

You want me to do what???

  • Upload
    jess

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

You want me to do what???. Refactoring legacy applications aka : fixing someone else’s “bad” code. Niel Zeeman Team Foundation Consulting [email protected]. Team Foundation. Consulting. Who am I…. projects. Altering internal structure without changing external behavior. - PowerPoint PPT Presentation

Citation preview

Page 1: You want me to do what???

You want me to do what???Refactoring legacy applications

aka : fixing someone else’s “bad” code

Niel ZeemanTeam Foundation [email protected]

Page 2: You want me to do what???

Who am I…

ConsultingTeam Foundationprojects

Page 3: You want me to do what???

Refactoring

Altering internal structure without changing external behavior

Page 4: You want me to do what???

RefactoringSmall transformations

Sequence of transformation can produce significant restructuring

Remain fully working

Page 5: You want me to do what???

WhatIf it stinks, change it.

—Grandma Beck, discussing child-rearing philosophy

Smells

Duplicated code

Long methods

Large classesLong param lists

Temporary fields

Mixed Responsibility

Anaemic domains

Page 6: You want me to do what???

WhyGive ability…..• Testability• Maintainability• Changeability• Comprehend ability• Applicability

Page 7: You want me to do what???

To Refactor

or

Not toRefactor

Code smellsIntuition Re-write

Deadlines

When

Page 8: You want me to do what???

How

Begin with the end in mind

Write SOLID code!

Page 9: You want me to do what???

SOLID

• Single Responsibility• Open - closed• Liskov substitution• Interface segregation • Dependency inversion

Page 10: You want me to do what???

Patterns

Extract Method Inline Method

Inline Temp

Replace method with method object

Extract class

Move method

Remove middle man

Replace data value with object

Replace record with object

Decompose conditional

Replace constructor with factory

method

Replace parameters with parameter object

Extract interface

Separate domain from presentation interface

Page 11: You want me to do what???

Patterns Add Parameter Change Bidirectional Association to Unidirectional Change Reference to Value Change Unidirectional Association to Bidirectional Change Value to Reference Collapse Hierarchy Consolidate Conditional Expression Consolidate Duplicate Conditional Fragments Convert Dynamic to Static Construction by Gerard M.

Davison Convert Static to Dynamic Construction by Gerard M.

Davison Decompose Conditional Duplicate Observed Data Eliminate Inter-Entity Bean Communication Encapsulate Collection Encapsulate Downcast Encapsulate Field Extract Class Extract Interface Extract Method Extract Package by Gerard M. Davison Extract Subclass Extract Superclass Form Template Method Hide Delegate Hide Method Hide presentation tier-specific details from the business

tier Inline Class Inline Method Inline Temp Introduce A Controller Introduce Assertion Introduce Business Delegate Introduce Explaining Variable Introduce Foreign Method

Introduce Local Extension Introduce Null Object Introduce Parameter Object Introduce Synchronizer Token Localize Disparate Logic Merge Session Beans Move Business Logic to Session Move Class by Gerard M. Davison Move Field Move Method Parameterize Method Preserve Whole Object Pull Up Constructor Body Pull Up Field Pull Up Method Push Down Field Push Down Method Reduce Scope of Variable by Mats Henricson Refactor Architecture by Tiers Remove Assignments to Parameters Remove Control Flag Remove Double Negative by Ashley Frieze and Martin

Fowler Remove Middle Man Remove Parameter Remove Setting Method Rename Method Replace Array with Object Replace Conditional with Polymorphism Replace Conditional with Visitor by Ivan Mitrovic Replace Constructor with Factory Method Replace Data Value with Object Replace Delegation with Inheritance Replace Error Code with Exception Replace Exception with Test Replace Inheritance with Delegation

Replace Iteration with Recursion by Dave Whipp Replace Magic Number with Symbolic Constant Replace Method with Method Object Replace Nested Conditional with Guard Clauses Replace Parameter with Explicit Methods Replace Assignment with Initialization by Mats

Henricson Replace Parameter with Method Replace Record with Data Class Replace Recursion with Iteration by Ivan Mitrovic Replace Static Variable with Parameter by Marian Vittek Replace Subclass with Fields Replace Temp with Query Replace Type Code with Class Replace Type Code with State/Strategy Replace Type Code with Subclasses Reverse Conditional by Bill Murphy and Martin Fowler Self Encapsulate Field Separate Data Access Code Separate Query from Modifier Split Loop by Martin Fowler Split Temporary Variable Substitute Algorithm Use a Connection Pool Wrap entities with session

Page 12: You want me to do what???

presentation

Business logicva

lidati

on

persistence

Page 13: You want me to do what???

DOMAIN

Page 14: You want me to do what???

Show m

e…

Page 15: You want me to do what???

Step 1

Extract Class / Controller

Page 16: You want me to do what???

Step 2

Separate Responsibilities

Page 17: You want me to do what???

Q&A

• http://refactoring.com/• http://sourcemaking.com/refactoring• http://goo.gl/WYIfV (MS PNP)• http://goo.gl/ostFM (MS Enterprise Patterns)

Niel ZeemanTeam Foundation [email protected]://blogs.teamfoundation.co.za