SOLID
Object-oriented programming design principles From Wikipedia, the free encyclopedia
In software programming, SOLID is a mnemonic acronym for five design principles intended to make object-oriented designs more understandable, flexible, and maintainable. Although the SOLID principles apply to any object-oriented design, they can also form a core philosophy for methodologies such as agile development or adaptive software development.[1]
Principles
Summarize
Perspective
Single responsibility principle
The Single-responsibility principle (SRP) states that "there should never be more than one reason for a class to change."[2] In other words, every class should have only one responsibility.[3]
Importance
- Maintainability: When classes have a single, well-defined responsibility, they're easier to understand and modify.
- Testability: It's easier to write unit tests for classes with a single focus.
- Flexibility: Changes to one responsibility don't affect unrelated parts of the system.[3]
Open–closed principle
The Open–closed principle (OCP) states that "software entities ... should be open for extension, but closed for modification."[4]
Importance
- Extensibility: New features can be added without modifying existing code.
- Stability: Reduces the risk of introducing bugs when making changes.
- Flexibility: Adapts to changing requirements more easily.
Liskov substitution principle
The Liskov substitution principle (LSP) states that "functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it."[5] [5]
Importance
- Polymorphism: Enables the use of polymorphic behavior, making code more flexible and reusable.
- Reliability: Ensures that subclasses adhere to the contract defined by the superclass.
- Predictability: Guarantees that replacing a superclass object with a subclass object won't break the program.[5]
Interface segregation principle
The Interface segregation principle (ISP) states that "clients should not be forced to depend upon interfaces that they do not use."[6][7]
Importance
- Decoupling: Reduces dependencies between classes, making the code more modular and maintainable.
- Flexibility: Allows for more targeted implementations of interfaces.
- Avoids unnecessary dependencies: Clients don't have to depend on methods they don't use.
Dependency inversion principle
The Dependency inversion principle (DIP) states to depend upon abstractions, [not] concretes.[8][7]
Importance
Origin
Software engineer and instructor, Robert C. Martin,[9][10][1] introduced the collection of principles in his 2000 paper Design Principles and Design Patterns about software rot.[10][7]: 2–3 The SOLID acronym was coined around 2004 by Michael Feathers.[11]
See also
References
Wikiwand - on
Seamless Wikipedia browsing. On steroids.