SOLID & Design Patterns Interview Question #8

What is the Interface Segregation Principle (ISP)?

SOLID Principles, Design Fundamentals, Repository, Factory, Strategy & Decorator Junior Beginner

Quick Interview Answer

The Interface Segregation Principle says clients should not be forced to depend on methods they do not use. Prefer focused interfaces representing specific capabilities over large general-purpose interfaces.

Detailed Explanation

The Interface Segregation Principle says clients should not be forced to depend on methods they do not use. Prefer focused interfaces representing specific capabilities over large general-purpose interfaces.

Smaller interfaces reduce unnecessary coupling and make implementations easier to test. A class may implement several focused interfaces when it supports multiple capabilities.

Code Example

public interface IPrinter
{
    void Print();
}

public interface IScanner
{
    void Scan();
}

public class MultiFunctionDevice : IPrinter, IScanner
{
    public void Print() { }
    public void Scan() { }
}