aspose file tools*
The moose likes Java in General and the fly likes When to use interface in an application ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "When to use interface in an application ?" Watch "When to use interface in an application ?" New topic
Author

When to use interface in an application ?

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Could someone please explain/elaborate the following two sentences on when to use interface :

1. If you need to change your design frequently,
you should prefer using interface to abstract.

2. Coding to an interface reduces coupling and interface
inheritance can achieve code reuse with the help of object composition.
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1281

You can use an interface when there is a need to have a central system or all other parts of your application is having something common between them then it's a good call to create an interface.

kaustubh


No Kaustubh No Fun, Know Kaustubh Know Fun..
Gokul Nanthakumar
Ranch Hand

Joined: May 11, 2010
Posts: 56
When you want to create a loosely coupled design Interface is the best pet.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Please search here on the ranch; there are other threads on similar subjects (for example in Beginning Java) which may be helpful.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

jose chiramal wrote:Could someone please explain/elaborate the following two sentences on when to use interface :

1. If you need to change your design frequently,
you should prefer using interface to abstract.

2. Coding to an interface reduces coupling and interface
inheritance can achieve code reuse with the help of object composition.


I think interfaces and abstract classes are good for both of those situations. The advantage an interface has is that your class can implement multiple interfaces and your class can have a parent class. With abstract classes, you are forced to extend the abstract class, preventing you from extending any other classes.


SCJP 6 || SCWCD 5
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
I earlier wrote:Please search here on the ranch; there are other threads on similar subjects (for example in Beginning Java) which may be helpful.
Try this thread too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When to use interface in an application ?