Five SOLID Principles

Why SOLID Principles important?

The SOLID principles’ overall purpose is to eliminate dependencies so that developers can update one part of software without affecting other parts. They’re also meant to make designs easier to comprehend, maintain, and extend. Finally, following these design principles helps software engineers avoid problems and create flexible, effective, and agile software.

While the principles have many advantages, adhering to them usually results in longer and more complex code. This means that the design process will take longer and development will be more complex. This extra time and effort, however, is well worth it because it makes program maintenance, testing, and extension much easier.

Follow these principles isn’t a cure, and it won’t prevent design flaws. The principles have gained popularity as a result of their potential to produce superior code in terms of readability, maintainability when followed correctly. In today’s world, all developers should be aware of and employ these ideas.

Why project should use SOLID principle?

Any developer that cares about your software product will surely strive to write high-quality code throughout the development process. Code complexity, coupling between classes, dividing responsibilities, and specifying their relationships are all best practices. These are some easy approaches to improve the internal quality of your code.

The first two articles in this series provide some best practices suggestions and improving software quality. However, we don’t delve too far into the SOLID coding philosophies.

What is SOLID Principles?

SOLID is an acronym for the first object-oriented design (OOD) principles by Robert C. Martine (also known as Uncle Bob)

These principles outline best practices for designing software while keeping in mind the project’s long-term maintenance and expansion. Adopting these techniques can also help you avoid code smells, restructure your code, and design Agile or adaptive software.

SOLID Principles are:

· S — Single-responsibility Principle

· O — Open-closed Principle

· L — Liskov Substitution Principle

· I — Interface Segregation Principle

· D — Dependency Inversion Principle

Single Responsibility Principle

According to this first concept, “a class must have just one cause to change,” i.e., it must have only one responsibility. This principle is concerned with cohesiveness. The functional affinity of a module’s elements is defined as cohesion. If the members of this module have a more direct and fundamental relationship, it refers to that relationship. As a result, the more well-defines our class is, the more coherent will be.

Open-closed Principle

“Software entities (classes, modules, functions, and so on) must be opened for an extension but close for modification, “. It specifies that we can extend the behavior of a class through inheritance, interfaces, and composition when appropriate. Nonetheless, we are unable to enable small changes to this class’s opening.

Liskov Substitution Principle

Derived classes must be substitutable for their base classes.

“Subtypes should be replaceable by their base types,” it states, implying that you should utilize inheritance with caution in your software project. Despite the fact that inheritance is a strong tool, it must be utilized in a contextualized and regulating manner to avoid classes being extended solely because they share a trait.

This idea was described by researcher Baebara Liskov in her 1998 study, which indicates that before selecting to inherit, we must consider the class’s preconditions and postconditions.

Interface Segregation Principle (ISP)

Make fine grained interfaces that are client specific.

“Many specific interfaces are better than a general interface,” it declares. This principle is concerned with interface cohesion, the creation of lean modules and the use of few behaviors. It’s difficult to maintain and evolve interfaces with a lot of different characteristics. As a result, it must be avoided.

Dependency Inversion Principle (DIP)

Depend on abstractions, not on concretions.

It says that we must “depend on abstraction and not on concrete classes.” Uncle Bob breaks the definition of this principle into two sub-items:

· “High-level modules should not depend on low-level modules. Both should depend on abstractions.”

· “Abstraction should not depend on details. Details should depend on abstractions.”

Abstraction are preferred since they vary less and make changing behavior and future code evolutions easier.

Conclusion

SOLID is an acronym for the first object-oriented design principles by Robert C. Martine (also known as Uncle Bob). Principles outline best practices for designing software. Adopting these techniques can help you avoid code smells, restructure your code, and design Agile or adaptive software. Many specific interfaces are better than a general interface, according to Uncle Bob’s Principle. Liskov Substitution Principle states that derived classes must be substitutable for their base classes. Dependency Inversion Principle says that we must depend on abstractions, not concretions.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store