-2

From a theoretical point of view, what are interfaces good for?

I know that they allow us to implement multiple inheritance; but are they widely used for something else?

Eagle One
  • 21
  • 5
  • Primarily interfaces used as Loose Coupling Endpoints. Please Do readd about it. – Pramod S. Nikam Jan 12 '15 at 10:54
  • They are more of a *design* choice. And please don't say that they allow us to implement *multiple inheritance*. *Java language doesn't support multiple inheritance*. They define an *unbreakable contract* which the *implementing* class should adhere to. – TheLostMind Jan 12 '15 at 10:55
  • possible duplicate of http://stackoverflow.com/questions/6916916/the-purpose-of-interfaces-in-java-language – sowieso-fruehling Jan 12 '15 at 10:57

3 Answers3

3

Interfaces help us to define abstraction for what some object is and how it should behave, while classes help us to implement that abstraction.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
0

An interface is a specifies what the object can do.

An abstract class specifies what an object is.

Zooty
  • 27
  • 1
  • 4
  • An interface specifies the *basic things that an instance of a class can do*. *An abstract class specifies what an object is.* - I don't get this line. – TheLostMind Jan 12 '15 at 10:57
  • The interface is more like a blueprint for a building, when you implement the interface you fill in the bricks. – Zooty Jan 12 '15 at 10:59
  • You can fill in the bricks.. paint your walls... place your windows.. and a lot of other things which the blueprint might not *have*.:P – TheLostMind Jan 12 '15 at 11:06
0

Interfaces allow you to define or classify similar types of behaviour across classes that are otherwise completely unrelated. You can do something similar with inheritance, but the classes are not loosely coupled.

See this great answer

Community
  • 1
  • 1
davek
  • 22,499
  • 9
  • 75
  • 95