Search code examples
javainheritanceclass-designabstract-class

Multiple abstract classes in multi-level inheritance


I have something like following:

public interface A
{ 
   ....
}

public abstract class AbstractClass implements A
{
   // Implements some methods from interface 
   ....
}

public abstract class GroupOne extends AbstractClass
{
   // Implements some methods from interface 
   // Define couple of abstract methods
   .....
}

public abstract class GroupTwo extends AbstractClass
{
   // Implements some methods from interface 
   // Define couple of abstract methods
   .....
}

public class ClassImpl extends GroupOne
{
   // Implement couple of abstract methods from GroupOne
}

public class AnotherClassImpl extends GroupTwo
{
   // Implement couple of abstract methods from GroupTwo
}

In my case, the interace and abstract classes are provided as part of the library. The application which uses this library needs to write the Impl classes extending the second level abstract ones. There is some common functionality to all classes in AbstractClass and then there is some group specific functionality in the group classes.

Is this a good desgin? The reason I am asking this is I have hardly come across class hierarchy that involved multiple abstract classes.


Solution

  • I see nothing wrong with such a design. ArrayList is one of the most commmonly used classes with two abstract parent classes. It could be useful to make the additional abstract methods of GroupOne and GroupTwo parts of interfaces extending the A interface.