The goal of the SOLID principles is to make our code more maintainable and extensible. While this is the ultimate goal, it’s not always the first step we take when starting a new project.
The SOLID principle are guidelines for writing good code that will be easy to change in the future. These principles are not absolute rules, but rather guides to help us write code that will be easy to maintain.
SOLID principles are especially important if you have ever worked with someone else’s code or inherited a project from another developer. It can be very difficult to understand what someone else was thinking when they wrote the code, so it’s important that you follow these guidelines in order to make any changes easier if need be in the future.
- You should use the
Single Responsibility
Principle to break your code into different classes. - You should use
Open/Closed Principle
to make sure that you can extend your code without having to change it. - You should use
Liskov Substitution Principle
to make sure that your objects behave as expected when passed around as arguments or returned from methods. - You should use
Interface Segregation Principle
so that your interfaces are more focused and easier to implement. - You should use
Dependency Inversion Principle
so that you can easily change the implementation of one class without affecting others
- You should use the
Tags:
design pattern