CSC/ECE 517 Fall 2009/wiki 2 If SJ
Refactoring If Statement with Polymorphism.
Design Consideration: Reuse and Change
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change'. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.
The Problem of If Statement
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.
Example of If statement
public class rename_method { static void badRenameMethod() { System.out.println("Hello, world!"); } }
Idea of Polymorphism
Definition of Polymorphism
Example of Refactoring Conditional Statement with Polymorphism
References
[1] Thomas Corbat, Lukas Felber, Mirko Stocker Refactoring Support for the Eclipse Ruby Development Tools, Diploma Thesis, HSR University of Applied Sciences Rapperswil Institute for Software.
[2] Code Refactoring Wiki, http://en.wikipedia.org/wiki/Code_refactoring.
[3] The First Workshop on Refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop
[4] Refactoring Tutorial for Ruby on Rails, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring
[5] Martin Fowler Refactoring: Improving the Design of Existing Code