Sobes.tech
Senior

Tell us about the Interface Segregation principle (the letter I in SOLID).

sobes.tech AI

Answer from AI

The Interface Segregation Principle (ISP) states that clients should not depend on interfaces they do not use. This means it is better to create several narrowly-focused interfaces rather than one large, universal interface.

For example, if you have an interface Printer with methods print(), scan(), fax(), a device that can only print should not implement the scan and fax methods. It is better to split the interface into Printable, Scannable, Faxable and implement only the necessary ones.

This increases flexibility, makes code easier to maintain and test, and reduces component coupling.