-6

I have been a developer for past 3 years and I have been seeing interface in most of the places as a contract for the developers to write their own implementation or a marker (eg. Serializable). But I quite dont understand how this concept is named as INTERFACE in literal meaning. Am I missing something pretty basic?

Tulains Córdova
39.6k13 gold badges102 silver badges157 bronze badges
asked Jan 9, 2017 at 7:17
11
  • What is the literal meaning of the word interface? For most of us the word fits the concept very well. Commented Jan 9, 2017 at 14:51
  • But the question is, I dont see interfaces in Java being used for interfacing... Then why? Commented Jan 9, 2017 at 15:09
  • If you have an object that implements an interface, then you can call the methods on that object that is defined in the interface and implemented in the object's class. When you call those methods, is that not interfacing with the object? Commented Jan 9, 2017 at 15:29
  • 2
    @RajaAnbazhagan: what is your personal definition of "Interfacing" then? Commented Jan 9, 2017 at 15:38
  • 2
    The point you seem to be missing is that you do not have to know what class an object is, you can use the methods as long you know that the object implements an interface. You can have a collection of objects that all implements the same interface but are from classes that do not have anything else in common than the interface. Then you can iterate over the collection and call the methods from the interface. I think you could benefit from reading up on programming to an interface not to an implementation to learn the strengths of interfaces. Commented Jan 9, 2017 at 19:24

2 Answers 2

8

Interfaces are the points in our world that describe how things interact with each other. User interfaces let users interact with applications, machines, and so on.

In programming interfaces are to be understood as the pre-defined interaction surface between two pieces of a program, or even multiple programs (hence API).

Interfaces are, of course, different in all programming languages but usually they operate on the same principle.

answered Jan 9, 2017 at 7:33
3

OK, based on this comment you made:

aren't classes and methods are also interfacing with Other objects...?

I think the point where you're getting confused is thinking that because it's called "interface" it does something that regular classes don't. But of course, any class's public members are effectively an interface in that sense.

The reason why Java interfaces are called so is that they are only an interface.

And they are most definitely used for interfacing in the sense of "a point where two systems, subjects, organizations, etc. meet and interact". For example, java.sql.Driver is an interface used to talk to an SQL database via JDBC.

But the concept is also useful within a system for more low-level interactions and since there are more of those, it gets used more often for that.

answered Jan 10, 2017 at 8:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.