DRY and SOLID clean code principles

Some clean code principles

DRY and SOLID clean code principles
Photo by Jozsef Hocza / Unsplash

DRY

Don't Repeat Yourself. Instead of duplicating code, move it into a function/class to be reused and easily maintained.

From: The Pragmatic Programmer by Andy Hunt and Dave Thomas

SOLID

  • Single responsibility: A class/module/function should have only one purpose.
  • Open-closed: A class/module/function should e open for extension but closed for modification.
  • Liskov substitution: Substituting a superclass with a subclass should not break the program.
  • Interface segregation: Don't add methods to an interface that isn't needed by all classes that will implement it.
  • Dependency inversion: high-level modules should depend only on abstractions (interfaces etc.). Low-level changes shouldn't affect high-level modules.

From: Robert C. Martin