Skip to content

The SOLID Design Principles πŸ‘¨β€πŸŽ“

Lyes S edited this page Jun 24, 2022 · 9 revisions

Table Of Contents

Single Responsibility Principle

  • Each class should be responsible for a single part or functionality of the system.
public class Entity {
    public void printTooMuchDetails() {}
    public void calculateEstimate() {}
    public void addEntityToDatabase() {}
}

The Entity class has three separate responsibilities: reporting, calculation, and database. This violate the SRP principle.

A better approach would be to separate the above class into three classes with separate responsibilities.

Open/Closed Design Principle

Liskov Substitution Principle

Interface Segregation Principle

Dependency Inversion Principle

Clone this wiki locally