SOLID Principles

Definition

SOLID Principles are OOP design principles which foster loose coupling and high cohension.

Single Responsibility Principle

A class should have only one responsibility. In the following example, the email sending logic is irrelevant to User class, therefore a separate class should be created for sending emails.

Open/Closed Principle

Software entities should be open for extension, but closed for modification. The class should be designed in such a way that new features can be added without modifying the existing code. This is usually achieved through separating interface from implementation. Main example of OCP is strategy pattern. You can extend new algorithms without making changes to the method in base class.

Liskov Substitution Principle

The derived classes should be perfectly substitutable for their base classes. This means the parent class’s original behavior or invariant shouldn’t change due to implementation of subclasses.

Interface Segregation Principle

Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one sub module.

Dependency Inversion Principle
The higher level modules should be coupled with the lower level modules with complete abstraction.