What Is Interface?

I started by software programming adventure when I was in the college. The earliest phase was when the focus was on programming skills more than the purpose of programming. The next phase was infactuation with C++ as an object oriented programming language – its possibilities, its standards, its flexibility and hence the complexity. I came across Java as another object oriented language and discovered “interface”. I found it interesting in the beginning, then intriguing and finally irritating. I could not understand the advantages of using an interface. I gathered from books that interfaces were useful in Java because it did not support multiple inheritance with classes. But this was not enough to convince me, and so I decided to indulge a bit to find out whether interfaces were indeed useful, or were just a syntactical binding on a programmer.

As I explored deeper, I read an article on Java World about interfaces and how they helped OOP in designing real-life scenarios. This made me wonder if we used interfaces in the real life. I started considering examples. Did I identify the driver of my bus as he drove the bus and not by his name, the conductor because he checked the tickets or the passengers because they travelled by bus? The same driver would become a passenter if he was travelling by the bus and not driving it. I realised that, however impersonal it my sound, I did identify certain people just by what they did and not by their name. Lots of real-life example started flashing before my eyes – the postman, the librarian, the doctor. I thought I had the answer to my question. This reached the next level when our usual postman was replaced by someone else, but he still did deliver the letter to me. This made me realise that “postman” was not the person but the role. So, the function of “delivering letters” applied to the role of the postman. I concluded that functionality or a set of functions defined roles.

After this newfound realisation, I began identifying everyone with what they did, and this helped me a lot in my software designing and programming activity. I had to understand “interface in real-life” to understand the applications of “interface in Java” which evolved to “interface in designing” with time. Using this I could call the same person a driver or a passenger, or could address another person as a driver. This way the transport system or I had to rely only on the driving ability, and not on any person for the driver’s role. What was required was to advertise for people who performed the function of driving. And I as a passenger did not need to know how driver drove the bus.

This is what interface does: It allows a system to isolate the “functionality” from an “entity” (living or non-living thing), leading the following possibilities:

  • Because the functionality was explicity identified, the transport system could use it to advertise its requirements.
  • The transport system knew the requirements for hiring more drivers, and could reduce its dependency on a single person.
  • The passengers did not need to know the technical details of driving the bus.
  • Whenever the requirements would change – e.g., the driver should also follow the traffic rules in addition to driving the bus – the transport system could change its functionality for the “driver” and make sure that all the drivers complied with this functionality. It helped the passengers of the transport system, as they did not need to depend on one person. The interface (functionality) of a driver became one of the ways in which the passengers started using the transport system. The passengers did not care from where the transport system got the dirvers or whether they were machines or humans as long as they “did their job” – “performed their functions” – “complied with the driver’s interface”.

I reached the conclusion that an interface is used by a server (transport system) to communicate with the clients (passengers).

The function pointers in the callback mechanisms or event handlers are interfaces of the functions. The function is invoked, wihtout needing to know how it is implemented.

When a C utilities library is built, the programs that use it don’t need to know the code inside the library, all they need to know is the signature of the functions to use. This set of functions is an interface.

Like in the case when the passengers did not need to know the technicalities of driving the bus, the interface allows to hide the implementation. It separates “what” from “how” of any system.

Technorati tags: , , , , , ,

This article is also available at ManojKhatri.com
Copyright Abhijit Nadgouda.

Discussion [Participate or Link]

  1. Abhijit Nadgouda @ iface » What Makes An Effective Interface? said:

    […] We have seen in the What Is Interface? post that an interface isolates the role (functionality) from the entity (who performs the functionality). This helps the servers (providers of the service) and its clients (users of the service) to communicate with each other. For the interface to be effective, the server should make sure that its language is understood by its clients. […]

  2. code::gallery :: Libraries, Toolkits And Frameworks :: May :: 2006 said:

    […] Some of these terms do overlap. API is the interface provided by the library, toolkit or the framework. This interface, usually, works like a contract between the creator and the user. Library is a generic term for a group of functionality provided. These libraries together can form a toolkit or a framework. Gang of Four (GoF) explain the difference between toolkits and frameworks in Design Patterns – Elements of Reusable Object-Oriented Software: A toolkit is a set of related and reusable classes design to provide useful, general purpose functionality. Toolkits don’t impose a particular design on your application; they just provide the functionality that can help your application do its job. They let you as an implementer avoid recoding common functionality. Toolkits emphasize code reuse. They are the object-oriented equivalent of subroutine libraries. […]

  3. code::gallery :: Two Exceptional Conversations on C++ :: June :: 2006 said:

    […] Titled as The C++ Style Sweet Spot and Modern C++ Style, the discussion answers some principle questions about moving from C to C++, using inhertiance the right way, using abstract classes for interface and considering the invariant for designing simple classes. If you haven’t read them yet, jump right ahead and consume them, the provide lot of food for thought and can act as design guidelines. […]

  4. iface thoughts » Blog Archive » Providing Web API said:

    […] The fifth point indirectly stresses on maintaining the interface. If it changes, keep it versioned. Let the developer realise that the version number has changed and take an appropriate action. Changes to interface without intimation can go terribly wrong for the users. Not only should the newer interface try to not deviate a lot from the older one, but also consider the migration for the users. […]

  5. iface thoughts » Blog Archive » What Makes An Effective Interface? said:

    […] We have seen in the What Is Interface? article that an interface isolates the role (functionality) from the entity (who performs the functionality). This helps the servers (providers of the service) and its clients (users of the service) to communicate with each other. For the interface to be effective, the server should make sure that its language is understood by its clients. […]

  6. iface thoughts » Blog Archive » Hey, I Am A Duck! said:

    […] The common aspect of all of these is that there still are objects and all of them have interfaces. In the static typing, dynamic binding and dynamic typing, this interface is explicitly mentioned in the code, whereas it is implicitly used in duck typing. […]

  7. iface thoughts » Blog Archive » OOP And FP said:

    […] I always like to confirm my understandings of the technology world with the real world. I always like to express benefits of technology in the layman’s language. Why? Because I feel that technology is just a means of solving problems and providing value in the real world. My peace of mind with Object Oriented Programming (OOP) stems from my conviction that it helps build the software as close as possible to the real world, which is the best possible case of automation. All my understanding of OOP is based on interface, not the keyword, but the concept. Things like these help me convince others why and what difference OOP can make. In business terms, provide the bottom-line justification. […]

  8. Open-Closed Principle on iface thoughts said:

    […] The answer, again, is abstraction. Abstraction enables you to have an interface which separates the intent from the implementation, or the what from the how. This opens possibilities for multiple hows for the same what. […]

  9. Interface Segregation Principle on iface thoughts said:

    […] All the basic design principles converge on the use of abstraction for incorporating flexibility using loose coupling behaviour. Interface Segregation Principle (ISP) is a guideline for designing different interfaces. […]

  10. Abstraction, Indirection, Simplification And Encapsulation on iface thoughts said:

    […] Abstraction is not data-hiding, it can be considered as a byproduct of separating what and how. Encapsulation is data hiding, but hiding only the unnecessary data. The user needs to know only the specifications to be able to use something. Which is where the significance of interface comes in. […]

  11. Code Quality As An Asset on iface thoughts said:

    […] Another reason that I have seen is inability to identify dependencies between various modules, components, or subsystems while developing. If module B depends on module A then A has to be ready before A can be developed. However, this linear development is not practical. What is required is to decide the communication between A and B, decide what A and B expect from each other or design their interface. Unless this is done it more than just probable that more time will be spent in redoing or rewriting code – one of the biggest hurdles in productivity. Identifying dependencies and designing interfaces is something that can help parallel development without having to rewrite. […]

  12. OOP In Procedural Programming on iface thoughts said:

    […] The key is that the interface abstraction is designed using the hook system. Node is the abstraction for any content type. The core of Drupal system uses these abstractions and is hence able to handle any extended content types without code modification. The use of node_invoke() to invoke any node hook. This means that the interface for communication with any node is designed using this abstraction. Node and hook system together enable Drupal to comply with Open-Closed Principle. […]

  13. More On Interface on iface thoughts said:

    […] One of my favorite authors has written on one of my favorite topics. Martin talks about role interface and header interface. A header interface is an explicit interface that mimics the implicit public interface of a class. Essentially you take all the public methods of a class and declare them in an interface. You can then supply an alternative implementation for the class. […]

  14. sonali said:

    great observation and relation to real life mate…
    very simple n clear to me now…
    thnx n keep it up…

  15. Abhijit Nadgouda said:

    Thanks Sonali.

  16. vikram said:

    Very beautifully explained. really very very helpful

  17. How Interface Helped Me | iface thoughts said:

    […] I cannot deny that it gave me a chance to improve my designing ability. It is not the keyword, but the concept of an interface that helped me. To an extent that it has been my channel of thinking for understanding newer […]

  18. Sreeram said:

    Beautifully explained. Talking in layman’s term is an art 🙂

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.