Skip to content

Instantly share code, notes, and snippets.

@yang-wei
Last active May 25, 2021 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yang-wei/8d0056c4699b02808ca38c672369418f to your computer and use it in GitHub Desktop.
Save yang-wei/8d0056c4699b02808ca38c672369418f 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