In JBuilder, it is very easy to move the domain and method in the inheritance system of the class by refactoring. This explains this refactoring function, we first look at the following class inheritance system:
Figure 15 Inheritance class diagram of Class
The animal class is cat and horse and parent class, and animal contains two domain and one method. You can move the range of animal in a class to a subclass. In addition, you can refine the superclass and interface for animal.
1. Relocation method
Open the Animal.java and position the cursor at the Howl () method, using Ctrl+shift+r->push down method to call up the Move Down Methods dialog box:
Figure 16 Move Down method
· Method: The way to move down.
· Keep as abstract in the current class: Indicates that the class is converted to an abstract class while the next method is moved.
· Selected Subclasses: Lists all subclasses of the current class, by default the method moves down to all subclasses, we cancel cat and move howl () down to horse only.
In the method Howl (), a private variable, animal, that is referenced to the class, volume, is changed to protected int volume after the Howl () is moved.
Push and move down are the opposite actions that are responsible for pushing the methods in the subclass into the parent class. Save and recompile the project, open Horse.java and place the cursor at the Howl () method: Ctrl+shift+r->pull up to pull up the dialog box:
Figure 17