• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Interface Inheritance

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one explain Interface Inheritance .

I found this on wikipedia.
http://en.wikipedia.org/wiki/Interface_inheritance
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The CanadaRequest interface inherits the stuff in the Request interface.

So, an implementation class would need to implement both doSomethingFancy() and getCanadianToken().

Example,

 
Rajshekhar Anand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James.

I understood the idea behind it , by the example you provided.

but what is the advantage of extending an interface and then implementing it as compared to a single interface having both the method .

It will be great if you can provide some link explaining above in detail .


-Gaurav
[ June 12, 2008: Message edited by: Gaurav Sinha ]
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but what is the advantage of extending an interface and then implementing it as compared to a single interface having both the method .



Good question. Before going into detail about the design decisions you are asking about, let us understand that to design software effectively, the design must be based on actual requirements. It is the "requirements" that will mostly influence design decisions about doing things in a certain way.

To answer your question clearly, we would need some requirements. Then after analyzing the requirements, you would be able to determine the advantages on designing in this fashion.

Without requirements, I can give you some hypothetical scenarios to think about.

What if you did not have the ability to alter the base interface?

Interface is part of some required third-party code.


What if there are many interfaces that inherit from the base interface?
The following would not make much sense:



Note, these are simple examples with only a single method in each interface. Other scenarios might include interfaces with 10 or 20 methods. It would not be good to copy and paste these method signatures all over the place (even though you certainly could if you wanted to). This is the difference between good and bad software design. Hence, interface inheritence.
[ June 12, 2008: Message edited by: James Clark ]
 
Rajshekhar Anand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James .
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in evolving software and design, i often perceive another reason when interface inheritance is used.

if things are evolving and you want to extend an interface by adding behaviour to it (interface requirements changed) it is often easier to just extend it instead of adding methods to existing interface. thus you don't affect client code which is still based on simple interface (by using or implementing it).

of course you could get to one point of a interface-extending-hell (very deep and wide hierachy). then you should consider to refactor.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic