Interface Segregation Principle

No client should be forced to depend on methods it does not use.

Identifying ISP Violations

  • Fat interfaces (too many methods);

  • Interfaces with low cohesion (methods that don’t relate or really belong together);

  • Empty method implementations;

Fat interfaces may be the a consequence of breaking the Single Responsibility Principle. An interface have a single responsibility.

Printing, scanning and faxing are three different concepts. No single interface should really handle all those concepts

By segregating the interfaces, we indirectly end up following the Liskov Substitution Principle, because we can replace the class type CannonPrinter with the interface Print, and vice-versa.

Most of the SOLID Principles are intricately linked to one another.

SOLID Principles complement each other, and work together in unison, to achieve the common purpose of well-designed software.

@startuml
skinparam DefaultFontName Source Code Pro
skinparam DefaultFontSize 15

interface Print {
  +print(): void
  +getPrintSpoolDetails(): String
}

interface Scan {
  +scan(): void
  +scanPhoto(): void
}

interface Fax {
  +fax(): void
  +internetFax(): void
}

class XeroxWorkCenter {
  +print(): void
  +getPrintSpoolDetails(): String
  +scan(): void
  +scanPhoto(): void
  +fax(): void
  +internetFax(): void
}

class HPPrinterAndScanner {
  +print(): void
  +getPrintSpoolDetails(): String
  +scan(): void
  +scanPhoto(): void
}

class CannonPrinter {
  +print(): void
  +getPrintSpoolDetails(): String
}

Print <|.up. XeroxWorkCenter
Scan <|.up. XeroxWorkCenter
Fax <|.up. XeroxWorkCenter

Print <|.down. HPPrinterAndScanner
Scan <|.down. HPPrinterAndScanner

Print <|.down. CannonPrinter
@enduml