What Is an Interface in Programming?
A contract that defines what an object can do, without saying how.
What an interface is
In programming, an interface is a contract that defines what methods a type must provide, without specifying how those methods actually work. It lists a set of capabilities, the things an object must be able to do, and any object that fulfills the interface must provide those capabilities. The interface says 'what,' not 'how.' This concept is central to writing flexible, well-organized object-oriented code, because it lets different objects be used interchangeably as long as they honor the same contract.
A contract, not an implementation
The key idea is that an interface is a promise. If a type 'implements' an interface, it promises to provide all the methods the interface requires. But the interface itself contains no actual working code, just the list of required methods. Each type that implements the interface supplies its own version of those methods. This separation between what must be done (the interface) and how it is done (the implementation) is what makes interfaces so useful.
Enabling interchangeable code
Interfaces let you write code that works with any object fulfilling a given contract, regardless of its specific type. For example, code that works with anything 'drawable' can handle any object that implements a Drawable interface, circles, squares, images, without caring what they are specifically. This makes code flexible and extensible: you can add new types later, and existing code will work with them automatically, as long as they implement the expected interface.
Interface vs. class
An interface differs from a class. A class is a blueprint that defines both what an object has and how it works, including actual code. An interface only defines what methods must exist, leaving the how entirely to the classes that implement it. A class can implement an interface, committing to provide the required methods. In short, a class is a full definition, while an interface is a contract that many different classes can agree to fulfill.
Interfaces and polymorphism
Interfaces are a key enabler of polymorphism, the ability to use one uniform way of interacting with many different types. Because all objects implementing an interface share the same set of methods, code can treat them uniformly while each provides its own behavior. This lets you write general, reusable code that automatically works with any type honoring the contract. Interfaces and polymorphism together are a powerful foundation for flexible software design.
Why it matters
Interfaces are a fundamental tool for writing flexible, maintainable object-oriented code. Understanding them clarifies how programs let different types be used interchangeably, how they stay open to new types without rewrites, and how the 'what' of behavior is separated from the 'how.' For anyone learning object-oriented programming, interfaces are an essential concept that underpins much of how well-designed, adaptable software is structured.
Related on Skillo
See also: What is polymorphism? Explained simply, What is a class in programming?.
Sources
Published date reflects the original event date (2024-04-02). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Written by
Skillo Staff
0 Comments
Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.