Let’s know SOLID Principle
The SOLID principles were first introduced by Robert C. Martin in his 2000 paper “Design Principles and Design Patterns.”
The principles have been widely adopted by the software development community, and they are considered to be essential for writing good object-oriented code.
SOLID is a set of five object-oriented design principles that help developers create more maintainable, flexible, and extensible code.
The principles are:
1️⃣ 𝗦𝗶𝗻𝗴𝗹𝗲 𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗶𝗯𝗶𝗹𝗶𝘁𝘆 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗦𝗥𝗣): A class that represents a user should only be responsible for storing and retrieving user data. It should not also be responsible for logging user activity or sending email notifications.
2️⃣ 𝗢𝗽𝗲𝗻/𝗖𝗹𝗼𝘀𝗲𝗱 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗢𝗖𝗣): Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. This means that a new functionality should be added by extending the software entities without modifying the existing code.
3️⃣ 𝗟𝗶𝘀𝗸𝗼𝘃 𝗦𝘂𝗯𝘀𝘁𝗶𝘁𝘂𝘁𝗶𝗼𝗻 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗟𝗦𝗣): A subclass should not break the behavior of its base class. For example, if the base class Animal has a method called makeSound() that barks, then the subclass Dog should also bark when the makeSound() method is called.
4️⃣ 𝗜𝗻𝘁𝗲𝗿𝗳𝗮𝗰𝗲 𝗦𝗲𝗴𝗿𝗲𝗴𝗮𝘁𝗶𝗼𝗻 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗜𝗦𝗣): An interface should only expose the methods that are needed by its clients. For example, an interface for a shape should not expose a method for calculating the perimeter of the shape if the shape does not have a perimeter.
5️⃣ 𝗗𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝘆 𝗜𝗻𝘃𝗲𝗿𝘀𝗶𝗼𝗻 𝗣𝗿𝗶𝗻𝗰𝗶𝗽𝗹𝗲 (𝗗𝗜𝗣): A module should not depend on another module that is at a lower level of abstraction. For example, a module that represents a user should not depend on a module that represents a database. Instead, the user module should depend on an abstraction, such as an interface for a repository.
Each of these principles provides a specific way to structure and organize code so that it’s easier to maintain, understand, and expand.