Thursday, February 5, 2026

Interface - An interface defines what to do, not how to do it.

1. What is an Interface?

An interface is a contract.
It defines what methods or properties a class must have, but not the implementation.

2. What can an interface contain?

  • Method declarations

  • Properties

  • Events
    👉 No method body (before C# 8.0)

3. How do we use an interface?

  • A class implements an interface

  • The class must implement all methods of the interface

4. Syntax example (interview-friendly)

interface IEmployee
{
    void Work();
}

class Developer : IEmployee
{
    public void Work()
    {
        // implementation
    }
}

5. Multiple inheritance support

  • C# does not support multiple inheritance with classes

  • But a class can implement multiple interfaces

class MyClass : IInterface1, IInterface2
{
}

6. Interface vs Abstract Class (short point)

  • Interface → 100% abstraction

  • Abstract class → Partial abstraction

7. Why do we use interfaces?

  • Loose coupling

  • Dependency Injection

  • Multiple inheritance

  • Better maintainability and testability

8. Important interview one-liner

An interface defines what to do, not how to do it.