SOLID software principles is the set of principles put forward by Robert C. Martin, which ensures that the software developed is flexible, reusable, sustainable and understandable and prevents code repetition. So the main purpose of these principles are, in order to easily adapted to requirements in the future and easier to add new features without the need to change anything in your code and also minimal change in code despite the new requirements and minimize the loss of time caused by the problems, such as the continuous correction on the code or even re-writing to code.
We have five principles.
1. Single Responsibility Principle
A class should have only one reason to change, i.e., it should have only one responsibility or job to do. This principle helps to keep classes focused, and makes them easier to understand, test, and maintain.
Example:
2. Open Close Principal
Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. In other words, you should be able to add new functionality to a system without changing its existing code. This principle promotes the use of inheritance and polymorphism to achieve this goal.
Example:
3. Liskov Substitution Principle
Subtypes must be substitutable for their base types. This principle states that any object of a derived class should be able to replace an object of its base class without causing any problems or errors. This principle ensures that inheritance is used correctly and that objects are well-behaved in a system.
Example:
4. Interface Segregation Principle
Clients should not be forced to depend on interfaces they don't use. This principle suggests that it's better to have many smaller interfaces than one large interface. This promotes decoupling and helps to prevent changes in one part of the system from affecting other parts.
Example:
5. Dependency Inversion Principle
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 promotes the use of interfaces and dependency injection to decouple modules and improve their flexibility and maintainability.
Example:
These are the main principles in software development and all these principles is very similar to each other.
No comments:
Post a Comment