Alex Rivera | Logout

Why do we need interfaces in Java?

Asked 2010-08-20T05:36:16.617
75

In Java to implement multiple inheritance we use interfaces. Is it the only use of interfaces? If yes, what is the main use of interface in Java? Why do we need interfaces in Java?

Edit
Report

1 Answer

20

In addition to these responses I would say the most important use for interfaces is to reduce coupling between components in your software.

An interface allows to represent an agreement between classes on how they will talk to each other without being tied to the actual implementations.

This allows us to replace implementations by others (very useful for testing, or changing use cases) without changing the compiled code.

answered 2010-08-20T06:13:21.423

Your Answer