/solid-principles

A clear declaration for SOLID principles with examples.

Primary LanguageTypeScript

SOLID Principles

SOLID principles are a set of design principles that aim to make software systems more maintainable, flexible, and scalable. Each letter in the acronym SOLID represents a principle.

  • Single Responsibility Principle (SRP):
    • A class should have only one reason to change, meaning it should have a single responsibility. This principle encourages you to design classes that are focused on doing one thing well.
  • Open-Closed Principle (OCP):
    • Software entities (classes, modules, functions) should be open for extension but closed for modification. This principle promotes designing systems that can be easily extended without modifying existing code.
  • Liskov Substitution Principle (LSP):
    • Subtypes must be substitutable for their base types. This principle ensures that objects of a superclass can be replaced with objects of its subclasses without affecting the correctness of the program.
  • Interface Segregation Principle (ISP):
    • Clients should not be forced to depend on interfaces they do not use. This principle encourages separating interfaces into smaller, more specific ones so that clients only need to depend on the interfaces that are relevant to them.
  • Dependency Inversion Principle (DIP):
    • High-level modules should not depend on low-level modules. Both should depend on abstractions. This principle promotes loose coupling and allows for easier changes and substitutions in the system.