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
Joined: Oct 13, 2005
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.