Interface Segregation Principle

TopicSource
๐Ÿงน Clean CodeClean Code - Udemy

Many client-specific interfaces are better than one general purpose interface.

Instead of trying to create on interface that fits all purposes, consider creating several smaller interfaces, that fit each use case. This gives you much more flexibility which functionality you want to implement.

Big general purpose interfaces can lead you into the trap that your specific class needs to implement a function, that it actually doesn't need.

interface Database {
  storeData(data: any);
}

interface RemoteDatabase {
  connect(uri: string);
}

class SQLDatabase implements Database, RemoteDatabase {
  connect(uri: string) {
    // connecting...
  }

  storeData(data: any) {
    // Storing data...
  }
}

class InMemoryDatabase implements Database {
  storeData(data: any) {
    // Storing data...
  }
}


  1. Liskov Substitution Principle