SOLID (object-oriented design)

SOLID is a mnemonic acronym for a group of five good principles (rules) in computer programming. SOLID allows programmers to write code that is easier to understand and change later on. SOLID is often used with systems that use an object-oriented design. 

SOLID was promoted by Robert C. Martin but the name itself was created by Michael Feathers.  

In essence, SOLID principles guide developers towards creating code that is more maintainable, flexible, and reusable. By adhering to these principles, one can build software systems that are easier to understand, modify, and extend over time. 

 SOLID Principles

 Single responsibility principle (SRP) 

Class has one job to do. Each change in requirements can be done by changing just one class.

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.
 Open/closed principle (OCP)  
Class is happy (open) to be used by others. Class is not happy (closed) to be changed by others.
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 (LSP)  
Class can be replaced by any of its children. Children classes inherit parent's behaviours.
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.
 Interface segregation  principle (ISP) 
When classes promise each other something, they should separate these promises (interfaces) into many small promises, so it's easier to understand.
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 (DIP)  
When classes talk to each other in a very specific way, they both depend on each other to never change. Instead classes should use promises (interfaces, parents), so classes can change as long as they keep the promise.
Importance
Loose coupling: Reduces dependencies between modules, making the code more flexible and easier to test.
Flexibility: Enables changes to implementations without affecting clients.
Maintainability: Makes code easier to understand and modify.
Related pages
 Programming
 Systems theory
 Social psychology
 Computer science
 Information technology

 References 

Category:Acronyms
Category:Computer programming