Show in graph

Software → Software Design

ISP

Clients should not be forced to depend on interface members they do not use.

Motivation

ISP solves the problem of “fat interfaces.” When a client depends on methods it does not use, unrelated changes can force unnecessary implementation work and coupling.

Where it fits

ISP belongs to SOLID and software design. It is closely connected to API design, dependency inversion, and modular boundaries.

Code example
Bad example
Python
class OrderRepository:  def save(self, order): ...  def find_by_id(self, order_id): ...  def export_csv(self): ...class CheckoutService:  def __init__(self, repository):      self.repository = repository  def checkout(self, order):      self.repository.save(order)
Good example
Python
class OrderWriter:  def save(self, order): ...class OrderExporter:  def export_csv(self): ...class CheckoutService:  def __init__(self, writer):      self.writer = writer  def checkout(self, order):      self.writer.save(order)

Common mistakes

  • Making every method its own interface.
  • Designing interfaces around implementation classes instead of client needs.