[Design Pattern]What is SOLID in Object Oriented Design ?

SOLID - 5 Principles of Object Oriented

Single Responsibility Principle :

  • A type should only have one reason to change
  • Separation of concerns - different types/packages handling different, independent tasks/problems

Open-Closed Principle

  • Types should be open for extension but closed for modification

Liskov Substitution Principle

  • You should be able to substitute an embedding type in place of its embedded part

Interface Segregation Principle

  • Don’t put too much into an interface; spilt into separate interfaces
  • For instance: There is an Animal interface with Walk method and Swim method, and Monkdy and Fish belong to Animal interfacel. For Monkey, Swim method is not implemented. For Fish, Walk method is not implemented. For the situation, it has break the Interface Segregation Principle. We should have two interface Terrestrial with Walk method & Aquatic with Swim method both included in Animal interface, so Monkey implement Walk method belong to Terrestrial interface and Fish implement Swim method belong to Aquatic interface.

Dependency Inversion Principle

  • High-level modules should not depend upon low-level ones; use abstractions (interface) to connect between high and low level modules
  • So when you modify low level modules, you don’t have to modify high level modules at the same time.

最後祝福努力認真的各位 “All your dream of are hidden in your daily life” 我們峰頂見!!!