Extract superclass(I)
11 March 2008Inheritance is a very useful feature that object oriented languages provide. Normally you write parent class first and then the child class. When the design of the application is not final, you tend to put more code in a class than required. At some instance, you realize, that you may make a super class and put some methods in it. Eclipse provide an easy way to do this.
Lets take an example. We have following class:
public class CSVFile{ public static void main(String[] args) { // TODO Auto-generated method stub } public ArrayList extractHeader() { return null; } public int getNoOfRows() { return 0; } public ArrayList extractContents() { return null; } }
We realised that extractHeader, extractContents and getNoOfRows should be in super class and CSVFile should inherit from it. We can do that by creating a new class and copying the code from CSVFile class.
Simple way is to use Eclipse Refactor feature.
Read the next post for this.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Extract superclass(I)