What Is an Interface?
To understand what an interface is let's start with an analogy. Any of the tools in a Swiss army knife is analogous to an interface. A Swiss army knife has a set of tools, such as a blade, can opener, screwdriver, and so on. But it is still a Swiss army knife; it is neither a blade, nor a can opener. It can perform the same actions as a can opener or a screwdriver, without being one. From the point of view of someone who needs a can opener, a Swiss army knife acts like a can opener. From the point of view of someone who needs a screwdriver, the same Swiss army knife is a screwdriver. In programming you would say that the can opener, blade, and so on are interfaces that define certain capabilities, and the Swiss army knife ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access