SOLID

SOLID is an acronym for Single responsibility, Open-Closed, Liskov substitution, Interface segregation and Dependency inversion principles.

Single Responsibility Principle (also known as SRP): This principle states that a unit of software -a function, a class, a module...- should only have one responsibility, one thing to do, one objective. This increase the composability of the unit.

Open-Closed principle: This principle states that a class should be opened to extension and close to modification. So you should not modify the class but extend it using inheritance or composition.

Liskov substitution principle: This one says that for each place you can use a parent object you should be able to use any of its children. So, if you have an Animal class and a Cat class, you should be able to use Cat on those places you can use Animal, but also Dog.

Interface segregation principle: This principle states that no class should be forced to implement unneeded methods. To avoid this, we should separate methods in different interfaces so each class can implement only the needed interfaces. [more in interface segregation principle]

Dependency inversion principal: This one says that objects should depend on generalizations instead of concretions. Don't confuse with dependency injection, as you can inject classes by constructor parameter and at the same time this classes can be concretions, so you don't met dependency inversion.

Back to the glossary