



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1
2
The requirements of real software often change in ways that cannot be handled by the current design Moreover, trying to anticipate changes in the initial implementation can be difficult and costly
Redesign as requirements change Refactor code to accommodate new design
3
You might break something in the code You have to update the documentation Both expensive
Makes the code harder to change Makes the code harder to understand and maintain Very expensive in the long run 4
Follow mechanical patterns (which could be automated in some cases) called refactorings , which are semantics-preserving
By rerunning all of your unit tests If something breaks, it s easy to know what you changed to cause the failure.
decompose large objects into smaller ones distribute responsibility
Adds composition and delegation (read: indirection) In some sense, refactorings are ways of applying design patterns to existing code
You are updating the design of your code, but not changing what it does. You can thus rerun existing tests to make sure the change works.
You are modifying the functionality of the code.
But know when you are using which hat, to be sure that you are reaching your end goal.
7
Give a method a more meaningful name; update callers
Pull out code in one method into a separate method
Remove code that assigns a method call to a temporary, and replace references to that temporary with the call
Move method from one class to another
8
Break a class that does many things into smaller classes
A class isn t doing very much, so inline its features into its users (reverse of Extract Class)
Basically replace state constants with typesafe Enum
Don t switch on a type code, rather do the work in the type object, and use delegation (second half of State)
9
http://www.eclipse.org
10
Bad code exhibits certain characteristics that can be addressed with refactoring; these are called smells.
e.g., invoking lots of get methods
Did this by moving extracting getCharge() out of Customer.statement(), moving it into Rental
Pulled getCharge() out of statement()
Replaced thisAmount with calls to getCharge()
19
[Ward Cunningham]
20
Complexity Changing design is hard, understanding code is hard Possibility to introduce errors Mitigated by testing Clean first Then add new functionality Cultural Issues Producing negative lines of code, what an idea! We pay you to add new features, not to improve the code! If it ain t broke, don t fix it We do not have a problem, this is our software!
http://www.refactoring.com/catalog/index.html
http://industriallogic.com/xp/refactoring/