Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Refactoring Mitch Soden Union College. Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation.

Similar presentations


Presentation on theme: "Program Refactoring Mitch Soden Union College. Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation."— Presentation transcript:

1 Program Refactoring Mitch Soden Union College

2 Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation tools

3 Definition Controlled/deliberate process Improve design/internal structure Existing code Behavior-preserving

4 Unit Testing Solid test suite - 1 st step in refactoring Test after each refactoring Should be automated & self-checking Focus tests based on risk

5 Example – Extract Method Make code fragment into method whose name explains the purpose.... // print banner System.out.println (“*********************”); System.out.println (“*** Customer Info ***”); System.out.println (“*********************”); // perform calculations while (x.hasMoreElements()) {... } // print details System.out.println (“Name: ” + name); System.out.println (“Balance: ” + balance);

6 Example – Extract Method Refactored code:... printBanner(); // perform calculations while (x.hasMoreElements()) {... } printDetails(balance); } void printBanner() { System.out.println (“*********************”); System.out.println (“*** Customer Info ***”); System.out.println (“*********************”); } void printDetails(double balance) {...

7 Example – Replace Error Code with Exception Make a method throw an exception instead of returning a special code to indicate an error. int withdraw(int amount) { if (amount > _balance) return –1; else { _balance -= amount; return 0; }

8 Example – Replace Error Code with Exception Refactored code: void withdraw(int amount) throws BalanceException { if (amount > _balance) throw new BalanceException(); _balance -= amount; }

9 Why Refactor? Problems Software modifications degrade structure Maintenance costs too high Inability to meet schedules

10 Why Refactor? Refactoring helps by Making software easier to understand Making software cheaper to modify Allowing developers become more productive

11 Limitations/Drawbacks Time Human factor Changing interfaces Non-object oriented languages

12 Just Another Software Engineering Practice? Immediate payback Personal benefits It feels good

13 Automation Tools Refactoring Browser –1 st refactoring tool built –Univ. of Illinois PhD work –Supports Smalltalk –Integrates w/ Smalltalk Browser

14 Automation Tools RefactorIt –Aqris Software, 2002 –Integrates w/ JBuilder, Forte, JDeveloper –Many common refactorings –Includes code metrics –Automates auditing and corrective actions

15 Questions, comments, opinions?


Download ppt "Program Refactoring Mitch Soden Union College. Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation."

Similar presentations


Ads by Google