I am new to java and learning interfaces. I did not understand the use of interfaces other than just standardizing the expectation.
If there is any other uses please help me to understand that.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Interfaces have a few good uses:
Polymorphism
They allow you to treat several different, but similar, objects in the same way. For example:
They also allow Objects to fit into several different boxes. For example, a
Birdnot only flies, but it is anAnimal. Interfaces allow you to treatBirdas either one:Decoupled Design
Additionally, they give you flexibility in choosing your implementation. (I’m not sure what you mean by “Standardizing the Expectation”, but this use is probably most related to standardization. i.e. This works because it creates a standard.) For example, say I have a method that returns a
List<Flyer>. SinceListis an interface, I can choose useArrayList,LinkedList, etc. as my implementation: