Skip to content

Instantly share code, notes, and snippets.



Last active May 25, 2021
What would you like to do?
SOLID Principles of Object Oriented and Agile Design

Encapsulation ?

  • OO weaken encapsulation by introducing private, public, protected

Inheritance ?

  • why Java doesn't have inheritance ? Diamond problem



Polymorphism is the one thing in OOP that solves the problems of a bad code which are rigidity, fragility and non-usability

Single Responsibility Principle (SRP)

  • responbility: sources of change
  calcPay()     // CFO
  reportHours()  // COO
  writeEmployee()  // CTO
// This class has 3 responbilities

Open/Closed Principle

modules should be open for extension, close for modification

  • for eg: when data source changed from rdb to file, we don't need to change the method
  • no switch statement

Liskov (LSP)

Rectangle <- Square
  • square is not substitubale for rectangle
  • that violates LSP and will add if/else to code

Interface Segregation Principle

  • Small interface instead of fat
  • compose if necessary

Dependency Inversion Principle (DIP)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment