Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Steven Wood   on Nov 19 In Java Category.

  
Question Answered By: Leonard Pierce   on Nov 19

if you study design patterns, one of the mottos is to design to
the interface. So, the reason as to why is all over the place. If you
go to Javaworld, you can find  an abundance of articles on why to
program to the interface.

An important reason to have interfaces  is to support multiple  type
inheiritance. Since classes are locked down to single implementation
inheiritance, i.e extending an abstract class, an interface  allows a
developer to make a contract so that an object can inheirit many types
via implements. Now, I can cast my object to the interface and work
with any object that implements the interface in a standard manner. In
this case, a sub perk of interfaces is revealed. It allows for objects
to be substituted by other objects that implement the same interface.
So, if I was to use an API that has been standardized by the JCP, then
I can utilize any vendors implementation of the interface without
having to worry about how the vendor implemented the API.

In addition, a spinoff is that it helps with multi-developer projects.
Some people like to develop apps by breaking it up into chunks. Well,
one of the tasks that comes before deployment is integration. If the
developers decide on an interface/API for the chunks, then the
developers can work seperately without too much impact to integration.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on why interfaces Or get search suggestion and latest updates.


Tagged: