Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is merging 2 classes into 1 class where one class is a subclass of the other called?

I have:

  • an abstract class A
  • an abstract class B that extends A
  • no other classes that extends A except B
  • other class(es) that extend B

To reduce the number of classes, I want A and B to be merged into one class, and let the other class(es) extend from the new merged class.

What is the name of this refactoring?

P.S. In my implementation it is in Java, can this refactoring be done automatically in IntelliJ?

like image 794
Randy Sugianto 'Yuku' Avatar asked Mar 04 '15 10:03

Randy Sugianto 'Yuku'


People also ask

Can a class be a subclass of two classes?

No, you can't.

What does it mean to be a subclass of another class?

Definitions: A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).

Can you be a subclass of multiple classes?

If more than one superclass defines a property, method, or event having the same name, there must be an unambiguous resolution to the multiple definitions. You cannot derive a subclass from any two or more classes that define incompatible class members.


2 Answers

IntelliJ's Inline Superclass performs the merging of a superclass to subclass.

Inline Superclass

like image 166
Kayaman Avatar answered Oct 11 '22 19:10

Kayaman


You will be inlining class A and intellij supports that. Just right click on the class name and select "refactor" from the pop-up and inlining the class should be an option.

like image 45
Erik Madsen Avatar answered Oct 11 '22 20:10

Erik Madsen