Sobes.tech
Junior — Middle

How is the principle of interface segregation implemented in real projects?

sobes.tech AI

Answer from AI

The Interface Segregation Principle in real projects is implemented by creating several specialized interfaces instead of a single general one. This allows clients to depend only on the methods that they actually need.

For example, instead of one large interface:

interface Printer {
    void print(Document d);
    void scan(Document d);
    void fax(Document d);
}

it's better to split into several:

interface IPrinter {
    void print(Document d);
}

interface IScanner {
    void scan(Document d);
}

interface IFax {
    void fax(Document d);
}

Classes can implement only the necessary interfaces, which simplifies support and extension of the code.

How is the principle of interface segregation… - sobes.tech