A look at the SOLID principles in action

SOLID is a set of principles that are used as guidelines for creating a clean and maintainable application that is also less buggy and error-prone.

Today, we will take a deep dive into the third principle of SOLID: the Liskov Substitution Principle. We will try to understand how this principle can help us to create a better and cleaner React application.

Other Articles in this Series

  1. Single Responsibility Principle
  2. Open Closed Principle
  3. Interface Segregation Principle
  4. Dependency Inversion Principle

What Is the Liskov Substitution Principle?

In simple terms, this principle says:

“Subclasses should be substitutable for their superclasses.”

That means subclasses of a particular class should be able to replace the superclass without breaking any functionality.

Example

If PlasticDuck is a subclass of Duck, then we should be able to replace instances of Duck with PlasticDuck without any surprises.

PlasticDuck is not a good substitution for Duck if it has a battery.

Source: Maksim Ivanov

That means PlasticDuck should fulfill all the expectations set by the Duck class.

#software-development #react #programming #javascript #web-development

Applying the Liskov Substitution Principle in React
1.70 GEEK