Code Craftsmanship

SOLID principle

SOLID stands for:

  • S: Single-responsiblity Principle
  • O: Open-closed Principle
  • L: Liskov Substitution Principle
  • I: Interface Segregation Principle
  • D: Dependency Inversion Principle

These are a lot of terms to remember, but the concepts are simple and easy to understand. The best way to learn them is to see them in action.


Single-responsiblity Principle

The single-responsibility principle (SRP) states that every module, class or function should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class, module or function.


Open-closed Principle

The open–closed principle (OCP) states that every module, cassl, or function should be open for extension, but closed for modification. That means that you should be able to extend a class's behavior, without modifying it. It is very important to make the distinction between extension and modification.

Extension means adding new functionality so adding new code. Modification means changing the existing functionality ie. changing the existing code.

Modification are dangerous because you can introduce bugs in the existing code. You can also break other parts of the code that depend on the existing code. Extension are often safer and more scalable.

Some design paradigms are perfect to apply open-close principle like the decorator pattern or the composition pattern.

Read this article about Keeping React components maintainable with Open-closed Principle.


Liskov Substitution Principle

Work in progress
This page is still under construction.
Please come back later.
or
Previous
KISS principle
Next
Tests