geekelo / dsa_practice

This repo is maintained just for the purpose of daily data structures and algorithm practice and proficiency
1 stars 0 forks source link

SOLID principles #12

Open geekelo opened 4 months ago

geekelo commented 4 months ago

The SOLID principles are a set of five design principles in object-oriented programming aimed at creating more maintainable, scalable, and flexible software systems. They were introduced by Robert C. Martin (also known as Uncle Bob) and have become fundamental concepts in software engineering. Here's a brief overview of each principle:

  1. Single Responsibility Principle (SRP):

    • A class should have only one reason to change.
    • Each class or module should have a single responsibility, encapsulating one cohesive aspect of the system's functionality.
    • This principle helps in making classes easier to understand, maintain, and refactor.
  2. Open/Closed Principle (OCP):

    • Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.
    • You should be able to extend the behavior of a module without modifying its source code.
    • This principle promotes the use of abstraction and inheritance to enable flexible and reusable code.
  3. Liskov Substitution Principle (LSP):

    • Objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program.
    • Subtypes must be substitutable for their base types without altering the desirable properties of the program.
    • Violating this principle can lead to unexpected behavior and breaks the principle of polymorphism.
  4. Interface Segregation Principle (ISP):

    • Clients should not be forced to depend on interfaces they don't use.
    • Interface segregation advocates for breaking down interfaces into smaller, specific ones tailored to the needs of the clients.
    • This helps in avoiding "fat" interfaces that include methods irrelevant to certain clients and reduces coupling between components.
  5. Dependency Inversion Principle (DIP):

    • High-level modules should not depend on low-level modules. Both should depend on abstractions.
    • Abstractions should not depend on details. Details should depend on abstractions.
    • This principle encourages loose coupling between modules by relying on abstractions, interfaces, or abstract classes to define dependencies, rather than concrete implementations.

Applying these SOLID principles can lead to code that is easier to understand, maintain, and extend, promoting better software design and architecture.