SOLID Flashcards
What is the “S”?
Single Responsibility Principle
What is the “O”?
Open/Closed Principle
What is the “L”?
Liskov Substitution Principle
What is the “I”?
Interface Segregation Principle
What is the “D”?
Dependency Inversion Principle
Benefits of Single Responsibility Principle
It makes your software easier to implement and prevents unexpected side-effects of future changes.
Also, classes, software components and microservices that have only one responsibility are much easier to explain, understand and implement than the ones that provide a solution for everything.
What is Single Responsibility Principle
A class should have one, and only one, reason to change.
Each class, software component, and microservice is responsible for one, and only one, thing.
How can Single Responsibility Principle be overused
A lot of classes with only one function can lead to many dependencies.
What is Open/Closed Principle
“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”
Write your code so that you will be able to add new functionality without changing the existing code.
Polymorphic Open/Closed Principle
Utilizes interfaces instead of superclasses to allow different implementations which you can easily substitute without changing the code that uses them. The interfaces are closed for modifications, and you can provide new implementations to extend the functionality of your software.
Benefits of Open/Closed Principle
Interfaces allow for modifications of the dependencies without changing the main app.
Liskov Substitution Principle
“Let Φ(x) be a property provable about objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T.”
Objects of a superclass shall be replaceable with objects of its subclasses without breaking the application.
Extends the Open/Closed Principle by focusing on the behavior of a superclass and its subtypes.
Interface Segregation Principle
“Clients should not be forced to depend upon interfaces that they do not use.”