SOLID Principles in programming

 If you follow, these principles you can improve the reliability of your code by working on its structure and its logical consistency.

The SOLID principles are:

  • The Open-Closed Principle (OCP)
  • The Liskov Substitution Principle (LSP)
  • The Interface Segregation Principle (ISP)
  • The Dependency inversion Principle (DIP)

In general, the SOLID principles are basic learning steps for every code developer but are usually ignored by those who does not consider the highest quality of code their absolute priority.

1) The Single-responsibility principle (SRP)

In other words, every component of your code (in general a class, but also a function) should have one and only one responsibility. As a consequence of that, there should be only a reason to change it.

2) The Open–closed principle (OCP)

You should need to modify the code you have already written to accommodate new functionality, but simple add what you now need.

3) The Liskov substitution principle (LSP)

Alternatively, this can be expressed as “Derived classes must be substitutable for their base classes”.

4) The Interface Segregation Principle (ISP)

In the contest of classes, an interface is considered, all the methods and properties “exposed”, thus, everything that a user can interact with that belongs to that class.

5) The Dependency Inversion Principle (DIP)

So, that abstractions (e.g., the interface, as seen above) should not be dependent on low-level methods but both should depend on a third interface.

Comments

Popular posts from this blog

What’s the Difference Between Docker and Kubernetes?

TestNG Listeners

Database Sharding