Skip to content

Instantly share code, notes, and snippets.

@eimfach
Forked from yang-wei/README.md
Created May 25, 2021 14:19
Show Gist options
  • Save eimfach/e673ef65deb1b20d8fab95cd1e1d49c5 to your computer and use it in GitHub Desktop.
Save eimfach/e673ef65deb1b20d8fab95cd1e1d49c5 to your computer and use it in GitHub Desktop.
SOLID Principles of Object Oriented and Agile Design

https://www.youtube.com/watch?v=TMuno5RZNeE

Encapsulation ?

  • OO weaken encapsulation by introducing private, public, protected

Inheritance ?

  • why Java doesn't have inheritance ? Diamond problem

Polymorphism

getChar
putChar

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
employee
  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