• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content







Total Views
Views on SlideShare
Embed Views



2 Embeds 11

http://www.linkedin.com 10
http://www.slideshare.net 1


Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Refactoring Refactoring Presentation Transcript

    • Dhaval Dalal software-artisan.com
    • dhaval.dalal@software-artisan.com John Thompson, the hatter makes and sells hats for ready money!
    • dhaval.dalal@software-artisan.com John Thompson, the hatter makes and sells hats for ready money!
    • dhaval.dalal@software-artisan.com John Thompson, the hatter makes and sells hats for ready money!
    • dhaval.dalal@software-artisan.com John Thompson, the hatter makes and sells hats for ready money!
    • dhaval.dalal@software-artisan.com John Thompson
    • dhaval.dalal@software-artisan.com Refactoring means improving the design after it has been written. Martin Fowler.
    • dhaval.dalal@software-artisan.com Development is a process of discovery and I don’t write impeccable code!
    • dhaval.dalal@software-artisan.com Any fool can write code that a computer can understand. Good programmers write code that humans can understand. The purpose of refactoring is to make the software easier to understand and modify. Martin Fowler.
    • dhaval.dalal@software-artisan.com  It improves the design of software  By repairing a highly coupled, non- cohesive design.  Helps to find bugs faster.  Helps to Program Faster.
    • dhaval.dalal@software-artisan.com  Duplicate Code  Indecent Exposure  Switch Statements  Divergent Change  Long Method  Shotgun Surgery  Long Parameter List  ...and many more. If it Stinks,  Large Class Change it!  Speculative Kent Beck Generality
    • dhaval.dalal@software-artisan.com  Encapsulate Collections  Encapsulate Downcast  Replace Error Code with Exception  Introduce Variable  Introduce Symbolic Constants  Rename Method/Variable  Remove Control Flag  Simplify Conditionals  Simply Nested Conditionals with Guard Clauses  Move Method  Chain Multiple Constructors/Methods  Replace Type Code with Enums or Class
    • dhaval.dalal@software-artisan.com  Replace Array with Object  Replace conditionals with Polymorphism  Replace Type Code with State/Strategy  Introduce Null Object ...and many more
    • dhaval.dalal@software-artisan.com Choose on appropriate Apply Refactoring Refactoring to apply No Reached Yes Run ALL Tests Desired Structure? (Get GREEN Bar) 11
    • dhaval.dalal@software-artisan.com  Let traffic continue to flow on old bridge.  Take an Interface- oriented approach.  House the old code in  Create another bridge one implementation. side-by-side the old one.  Create new refactored implementation.  When the new bridge is ready, delink traffic from the old one and re-route it  Use the new impl. by over the new bridge. replacing the old one. 12
    • dhaval.dalal@software-artisan.com  Arrive to pattern via series of small refactorings.  Rigorously apply OO principles along-side continuous refactoring.  SRP, OCP, LSP, ISP, DIP (SOLID) etc...  You will eventually evolve to some known pattern.  When you “intuit” that a pattern will readily apply.  Approach this in baby steps. 13
    • dhaval.dalal@software-artisan.com  Code without tests is Legacy.  Does anyone still create this?  Michael Feathers’ has an excellent book on this.  Working Effectively with Legacy Code  Refactoring code without tests is like performing a tight-rope walk without any safety net underneath. 14
    • dhaval.dalal@software-artisan.com
    • dhaval.dalal@software-artisan.com As in many things the answer lies in balancing opposing forces, especially when its difficult to make hidden Business Value explicit. Pragmatic Vs Dogmatic Agility Vs Fragility 16
    • dhaval.dalal@software-artisan.com  A traditionalist view on Refactoring is re-work!  In reality, it is responding to new information as it arrives.  At the same time, avoid “Major Refactorings”  Do high-level architecture envisioning. 17
    • dhaval.dalal@software-artisan.com Refactoring is no “silver bullet”, yet it is a valuable tool, a pair of silver pliers that helps you keep good grip on your code. Without refactoring, the design of the program will decay. Martin Fowler
    • dhaval.dalal@software-artisan.com  Refactoring  Martin Fowler.  Refactoring to Patterns  Joshua Kerievsky.  Refactoring Motivations  Jay Fields’ Blog  Creating an Agile Culture to drive organizational Change  David Anderson
    • Dhaval Dalal dhaval.dalal@software-artisan.com