SOLID: The First 5 Principles of Object Oriented Design
💥 𝐒𝐎𝐋𝐈𝐃
➡ 𝐒 – 𝐒𝐢𝐧𝐠𝐥𝐞 𝐑𝐞𝐬𝐩𝐨𝐧𝐬𝐢𝐛𝐢𝐥𝐢𝐭𝐲 𝐏𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞 (𝐒𝐑𝐏):
Each class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. This makes code more modular and easier to understand.
➡ 𝐎 – 𝐎𝐩𝐞𝐧/𝐂𝐥𝐨𝐬𝐞𝐝 𝐏𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞 (𝐎𝐂𝐏):
Software entities (classes, modules, functions) should be open for extension but closed for modification. This encourages the use of interfaces and abstract classes, facilitating future enhancements without altering existing code.
➡ 𝐋 – 𝐋𝐢𝐬𝐤𝐨𝐯 𝐒𝐮𝐛𝐬𝐭𝐢𝐭𝐮𝐭𝐢𝐨𝐧 𝐏𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞 (𝐋𝐒𝐏):
Subtypes must be substitutable for their base types without altering the correctness of the program. This ensures that derived classes can be used interchangeably with their base classes.
➡ 𝐈 – 𝐈𝐧𝐭𝐞𝐫𝐟𝐚𝐜𝐞 𝐒𝐞𝐠𝐫𝐞𝐠𝐚𝐭𝐢𝐨𝐧 𝐏𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞 (𝐈𝐒𝐏):
Clients should not be forced to depend on interfaces they do not use. It’s about creating specific interfaces tailored to the needs of the clients to avoid unnecessary dependencies.
➡ 𝐃 – 𝐃𝐞𝐩𝐞𝐧𝐝𝐞𝐧𝐜𝐲 𝐈𝐧𝐯𝐞𝐫𝐬𝐢𝐨𝐧 𝐏𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞 (𝐃𝐈𝐏):
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 promotes flexibility and ease of maintenance.
References: LinkedIn