What Is an Interface?
An interface is a contract. It lists the operations a type must provide, but says nothing about how those operations work. Any class that claims to follow the interface has to supply all of them.
The interface says what can be done: the method names, parameters and return types.
Each class that implements it decides how it is done: the method bodies.
Code that uses the interface does not need to know which class is behind it.
Key takeaway: the interface is the WHAT, the class is the HOW.
Real-world analogy: the USB-C port
A phone with a USB-C port does not care who made the charger. A wall charger, a laptop charger and a power bank all fit, because each one follows the same port standard. The phone depends only on the shape of the port, never on the charger behind it.
In code: the port standard is the interface, each charger is an implementation, and the phone is the code that depends on the interface.
In Low Level Design, interfaces let you hide details behind a clear boundary, swap one implementation for another without touching the rest of the code, test with fake implementations, and use polymorphism: one interface, many classes.
Interfaces vs Classes
So far you have seen classes like Member, Book and Booking that hold both data and behaviour. An interface is different:
A class has fields (data) and method bodies (behaviour).
An interface has only method signatures: no bodies and, in its pure form, no data.
Java and Go have an interface keyword. Python uses an abstract base class from the abc module. C++ has no keyword, so an interface is written as an abstract class whose methods are all pure virtual.
Key Properties of Interfaces
Behaviour without implementation. The interface only declares the operations. Each implementer is free to do the work its own way, as long as it keeps the contract.
Polymorphism. Different classes can implement the same interface, and calling code can use any of them through one type.
Decoupling. Code that depends on an interface is shielded from changes in the classes behind it. That makes it easier to extend, to test and to maintain.
Declaring an Interface
Our running example is a login flow that sends a one-time password (OTP). The login code should just say "sendOtp" and not care whether the code goes out by SMS or WhatsApp. Here is that contract in each language:
A few points about the C++ version, since it has no interface keyword:
virtual means a derived class can override the function, and = 0 makes it pure virtual, with no body here.
A class with at least one pure virtual function is abstract, so you cannot create an OtpSender object directly.
The virtual destructor makes sure the right destructor runs when an object is deleted through an OtpSender pointer.
In Go there is no implements keyword at all. Any type that has a SendOtp method with the same signature satisfies OtpSender automatically.
Implementing the Interface
Now two classes keep the contract, each in its own way:
The override keyword (C++) and @Override annotation (Java) ask the compiler to check that the method really matches the interface. A typo in the name or parameters then becomes a build error instead of a silent new method.
Depending on the Interface, Not the Class
The real benefit shows up in the code that uses the interface. LoginService below receives an OtpSender in its constructor and never mentions SMS or WhatsApp. Passing the dependency in from outside like this is called dependency injection.
Expected output
SMS to 98765 00001: Your login code is 4821
WhatsApp to 98765 00002: Your login code is 4821
The same startLogin code produced two different results, depending only on which object was passed in. This is polymorphism in action. In LLD terms, LoginService depends on an abstraction, not on a concrete class.
Why Interfaces Matter in LLD
They decouple high-level code from low-level details. LoginService knows nothing about SMS gateways, so changing the gateway never touches the login logic.
They support multiple implementations. You might start with SMS only and add WhatsApp or email later. Storage can be a local disk today and the cloud tomorrow, behind a Repository or Storage interface.
They make testing easy. In a unit test you pass a fake implementation that records what happened and makes no network calls.
They help you follow design principles: dependency inversion (depend on abstractions) and open/closed (add new implementations without editing old code).
In an interview, using interfaces in the right places shows that you design for change, not just for getting the first version to work.
Practical Example: Exporting Reports to Different Storage
A shop wants a daily sales report saved as a CSV file. In development it goes to a local folder, in production it is uploaded to cloud storage, and in unit tests it should not touch the disk or the network at all.
That is three different ways to do one job, which is a clear sign an interface is needed. ReportService depends only on ReportStorage:
Expected output
Saved sales-2026-10-16.csv to /var/reports (40 bytes)
Uploaded sales-2026-10-16.csv to bucket shop-reports
Test run saved: yes, files in memory: 1
Why This Design Works
ReportService never changes. Moving from disk to cloud is a one-line change where the service is created.
A new target, such as an FTP server or email attachment, is one new class that implements ReportStorage.
Tests are fast and safe. InMemoryStorage lets you check the CSV and the file name without writing anything anywhere.
Every save returns a result, so the caller can react when storage fails instead of assuming it worked.
Interfaces and Abstract Classes
The two are related, but not the same:
An abstract class can mix shared code, data fields and abstract methods. It says "this is a base with some parts left for you to fill in".
A pure interface has only method signatures and no data. It says "anything that can do these things fits here".
In C++ both are written the same way, as a class with pure virtual functions. It is a pure interface when it has nothing else.
Java and Python let a class implement many interfaces but extend only one class (Python allows more, but it gets messy fast). Go has no inheritance at all, only interfaces.
In a design discussion you might say: "OtpSender is an interface that SmsOtpSender and WhatsAppOtpSender implement" or "BaseExporter is an abstract class with shared formatting code and one abstract method".
When Should You Introduce an Interface?
You do not need an interface for every class. Ask these questions in order:
Will there be more than one implementation, now or soon? Different OTP channels, payment providers or storage targets are good examples.
Does the class talk to something outside your code, such as a database, a third-party API or the file system? Hiding that behind an interface keeps the details in one place.
Do you need a fake version in tests? If the real one is slow, costs money or needs the network, an interface makes testing easy.
If all three answers are no, a plain class is simpler and fine. You can always extract an interface later when a second implementation actually turns up.
Common Mistakes with Interfaces
An interface with only one implementation and no reason for more. It adds a file and a layer of indirection for no benefit.
Putting data fields into an interface-style class. Keep pure interfaces free of state, and move shared data to an abstract base class if you really need it.
Ignoring the result of interface calls. If save() or sendOtp() can fail, return a result and check it.
Forgetting the virtual destructor in C++. Deleting a derived object through an interface pointer without it is undefined behaviour.
Fat interfaces. One interface with ten unrelated methods forces every implementer to write code it does not need. Split it into small, focused interfaces.
Naming interfaces after a library instead of the job. ReportStorage describes what your domain needs; S3Client only describes one vendor.
Summary
An interface defines what operations a type must support, without saying how they are implemented. Classes that implement it supply the real behaviour, and the rest of the system depends only on the interface.
You saw:
The difference between classes and interfaces, and the three key properties of interfaces.
How to declare an interface in C++ (abstract class), Java, Python (ABC) and Go.
How multiple implementations (SMS and WhatsApp OTP senders, disk, cloud and in-memory storage) share a common interface.
How calling code depends on interfaces through dependency injection, which makes it flexible and easy to test.
When an interface is worth adding, and the common mistakes to avoid.