Sitemap

SOLID principles

2 min readApr 19, 2023

--

Press enter or click to view image in full size
Photo by Austin Distel on Unsplash

The SOLID principles are a set of guidelines that can help you design better software by making it more modular, maintainable, and extensible. They are particularly important in object-oriented programming, such as C#, where you have to deal with complex and interconnected objects. The SOLID principles are:

    Get Amir AYADI’s stories in your inbox

    Join Medium for free to get updates from this writer.

  1. Single Responsibility Principle (SRP): A class should have only one reason to change, which means it should have only one responsibility. This principle encourages you to keep your classes focused and modular, which makes them easier to understand, test, and maintain.
  2. Open-Closed Principle (OCP): A class should be open for extension but closed for modification. This means that you should be able to add new functionality to a class without modifying its existing code. This principle encourages you to use inheritance, composition, and interfaces to create flexible and extensible code.
  3. Liskov Substitution Principle (LSP): Subtypes should be substitutable for their base types. This means that you should be able to use a derived class wherever its base class is expected, without causing any unexpected behavior or errors. This principle encourages you to follow the “is-a” relationship between classes and avoid violating the contracts of base classes.
  4. Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. This means that you should define small and cohesive interfaces that contain only the methods that a client needs, instead of large and bloated interfaces that contain methods that are not relevant to the client. This principle encourages you to create focused and specialized interfaces that can be implemented by different classes.
  5. Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Instead, they should both depend on abstractions. This means that you should design your code in a way that allows you to swap low-level implementations without affecting high-level modules. This principle encourages you to use dependency injection, inversion of control, and other techniques to decouple your code and make it more modular.

By following the SOLID principles, you can create code that is easier to understand, test, and maintain, and that can adapt to changing requirements and technologies.

--

--

Amir AYADI
Amir AYADI

Written by Amir AYADI

Full Stack Developer | Software Engineer | Here to share my knowledge