File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Multiple Inheritance with Same Base Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multiple Inheritance with Same Base Interface" Watch "Multiple Inheritance with Same Base Interface" New topic
Author

Multiple Inheritance with Same Base Interface

Douglas Rapp
Greenhorn

Joined: Nov 29, 2011
Posts: 11
Hello,

So I've got something working that seems a little hokie to me, and I was wondering if the design is violating any best practices. I can elaborate more on why the design exists this way if need be, but for now, this is the situation:

I've got a single base interface, FunI. Then, there is another interface, MoreFunI, that extends the first interface (FunI). There is also an abstract class, AbsFun, that implements a couple of methods in the base interface (FunI). Finally, there is a concrete class, LotsoFun, that both extends AbsFun and implements MoreFunI. Also, there are no clashing method signatures between MoreFunI and AbsFun. The whole set up works fine, and doesn't produce any problems at compile time.

However, like I said, my concern is that I'm afraid that the design is violating some best practices, since there isn't a nice single chain of inheritance, and possibly asking for bugs to pop up in the future.

For reference, here is an example code snippet:


Thanks,
Douglas
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 123
I can not immediately give an example of where I have done something like this, but reading your example I can't say that anything jumps out at me as wrong. It seems you are more asking an object modeling question, i.e., does this interface design and class implementation make sense for the problems I am trying to solve and is there a different way that it should be modeled to support the solution.

If you have separated the desired behavior you wish to see isolated into FunI and MoreFunI and it makes sense as separated then I think you are ok.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

Douglas Rapp wrote:However, like I said, my concern is that I'm afraid that the design is violating some best practices

Not that I can see. I think the only question I would ask myself is whether LotsOFun shouldn't actually be an interface that extends the other two, and then hang a LotsOFunImpl class off that (although I suggest you find a better name); but only you can answer that one.

since there isn't a nice single chain of inheritance, and possibly asking for bugs to pop up in the future.
<My 2¢>
I think it's far more likely that bugs (or even more likely - brittleness) are likely to result from having long chains of inheritance.
extends is a bit old hat these days, and programmers often look for more flexibility using composition (Google it), coupled with sets of interfaces.
</My 2¢>

HIH.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i see no problem with it, but unless you will have need of the separate interfaces in some other project, i would just have one interface.


SCJP
Visit my download page
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
And welcome to the Ranch
Douglas Rapp
Greenhorn

Joined: Nov 29, 2011
Posts: 11
Thank you, all! I just wanted to get more than one set of eyes on this in case I was making a silly mistake.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Inheritance with Same Base Interface