SOLID

By Karol Bocian | February 12, 2020

SOLID

SOLID is a basic concept in object-oriented programming. It was introduced by Robert C. Martin, who gathered together five rules in one concept: SOLID. It is an acronym of 5 principles for good object-oriented programming:

  • Single responsibility principle
  • Open/closed principle
  • Liskov substitution principle
  • Interface segregation principle
  • Dependency inversion principle

Single responsibility principle

Every class should have only one responsibility (every class should have only one reason to change) — one purpose of existence.

Open/closed principle

All classes should be open for enlargement and closed for modifications.

Liskov substitution principle

The application should work correctly when we put in the base class place every derived class.

Interface segregation principle

Many small and dedicated interfaces are better than few and general.

Dependency inversion principle

High-level modules should not depend on low-level modules, but the dependence should result from abstraction.

Advantages

  • Better code readability.
  • Higher quality.
  • Cheaper maintenance.
  • Fewer bugs during development.
  • Easier testing.
  • Easier developing.
  • Lack of god-classes.

Disadvantages

  • Bigger effort during developing.

Summary

Use SOLID principles everywhere you can. These are the best practices. In special situations allow yourself to not use these rules to write code faster. Despite breaking SOLID, try to write good code.

All posts from mini project: Learn SOLID and OOP principles:

Sources

Main image

Materials

One thought on “SOLID

Comments are closed.