1

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.

2
  • 1
    seems good, although we don't really know the context. That design says that each of those classes behaves in a way the inteface defines. The Group classes share some methods (through AbstactClass) but implement some in a different way. Each group has another list of classes, that implement the desired methods in a very specific way. Are you sure you want that many abstract classes? If they make sense then it's good. Commented Jul 5, 2011 at 16:24
  • @c00kiemon5ter: Yes, that is right. Commented Jul 5, 2011 at 16:25

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.