Saturday, 15 September 2018

SOLID Principles

1) Single Responsibility Principle
 A class should have one, and only one, reason to change.

2) Open/Closed Principle
 Objects or entities should be open for extension, but closed for modification.

3) Liskov Substitution Principle  [LSP]
 Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.
 All this is stating is that every subclass/derived class should be substitutable for their base/parent class.
 In other words, as simple as that, a subclass should override the parent class methods in a way that does not break functionality from a client’s point of view.

4)Interface Segregation Principle
  A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.
  [Have smaller interfaces instead of one big interface]

5) Dependency Inversion
Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions. [Code for interface/abstract class instead of concrete classes]