170 likes | 282 Views
You want me to do what???. Refactoring legacy applications aka : fixing someone else’s “bad” code. Niel Zeeman Team Foundation Consulting nielz@teamfoundation.co.za. Team Foundation. Consulting. Who am I…. projects. Altering internal structure without changing external behavior.
E N D
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel ZeemanTeam Foundation Consulting nielz@teamfoundation.co.za
Team Foundation Consulting Who am I… projects
Altering internal structure without changing external behavior Refactoring
Small transformations Refactoring Remain fully working Sequence of transformation can produce significant restructuring
If it stinks, change it.—Grandma Beck, discussing child-rearing philosophy What Anaemic domains Duplicated code Mixed Responsibility Long methods Smells Temporary fields Long param lists Large classes
Why Give ability….. • Testability • Maintainability • Changeability • Comprehend ability • Applicability
To Refactor Not to Refactor When Code smells Deadlines or Intuition Re-write
How Begin with the end in mind Write SOLID code!
SOLID • Single Responsibility • Open - closed • Liskov substitution • Interface segregation • Dependency inversion
Decompose conditional Replace data value with object Replace parameters with parameter object Inline Temp Extract Method Inline Method Patterns Remove middle man Replace method with method object Move method Replace constructor with factory method Replace record with object Extract interface Extract class Separate domain from presentation interface
presentation persistence validation Business logic
Presentation Services Controllers View Models Repository DOMAIN
Step 1 Extract Class / Controller
Step 2 Separate Responsibilities
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 Consulting nielz@teamfoundation.co.za http://blogs.teamfoundation.co.za