Monday, 16 April 2018

Solid Principals

  • S stands for SRP (Single responsibility principle).
  • O stands for OCP (Open closed principle)
  • L stands for LSP (Liskov substitution principle)
  • I stand for ISP ( Interface segregation principle)
  • D stands for the DIP ( Dependency inversion principle)

How to learn in a sequence. Then you will get the better understanding.

1.  Single responsibility principle
2.  Interface segregation principle
3. Open closed principle
4. Liskov substitution principle
5. Dependency inversion principle


 Single Responsibility Principle (SRP)
  • Each class and module should focus on a single task at a time
  • Everything in the class should be related to that single purpose
  • There can be many members in the class as long as they related to the single responsibility
  • With SRP, classes become smaller and cleaner
  • The code is less fragile 

Interface Segregation Principle (ISP)
  • The interface-segregation principle (ISP) states that "no client should be forced to depend on methods it does not use".
  • This means, instead of one fat interface many small interfaces are preferred based on groups of methods with each one serving one sub-module.
  • The ISP was first used and formulated by Robert C. Martin while consulting for Xerox. 

Open/Closed Principle

In object-oriented programming, the open/closed principle states that "software entities such as classes, modules, functions, etc. should be open for extension, but closed for modification" 
  • Which means any new functionality should be implemented by adding new classes, attributes, and methods, instead of changing the current ones or existing ones.
  • Bertrand Meyer is generally credited for having originated the term open/closed principle and This Principle is considered by Bob Martin as "the most important principle of object-oriented design".

Liskov Substitution Principle (LSP)

Substitutability is a principle in object-oriented programming and it states that, in a computer program, if S is a Subtype of T, then objects of type T may be replaced with objects of type S 
  • Which means, Derived types must be completely substitutable for their base types
  • More formally, the Liskov substitution principle (LSP) is a particular definition of a subtyping relation, called (strong) behavioral subtyping
  • This Principle is introduced by Barbara Liskov in 1987 during her conference address on Data abstraction and hierarchy
  • This principle is just an extension of the Open Close Principle

Dependency Inversion Principle (DIP)
  • High-level modules should not depend on low-level modules. Both should depend on abstractions. 
  • Abstractions should not depend on details. Details should depend on abstractions.



No comments:

Post a Comment