Clean Code Flashcards
What is SOLID in clean code ?
SOLID are 5 principles introduced by Robert C.Martin (referred to as “Uncle Bob”) to make code more understandable, flexible and easier to maintain.
What are 5 SOLID principles ?
SRP : Single Responsibility Principle
OCP : Open/Closed Principle
LSP : Liskov Substitution Principle
ISP : Interface Segregation Principle
DIP : Dependency Inversion Principle
What is SRP ?
Definition : A class must have only one job/responsibility.
_______________________________________________
Why it matters : Making change on a class with a multiple tasks can impact other code.
What is OCP ?
Definition : Software entities ( class , function , module ) should be open for extensibility but closed for modification
______________________________________________
Why it matters : you can extend functionnalities of a system without changing the existing code, which makes code more reusable and reduce impact of code changing.
What is LSP ?
Definition : Objects of super class should be replaced with objects of child class without causing issues.
_______________________________________________
Why it matters : Reusable code , a child class can be used in the same way as its parent class.
_______________________________________________
=> if a child class cannot do all parent things we can replace the parent class with a new “third class” or “interface” so both the precedent parent and child class become child to a new parent class(or implements a common interface).
What is ISP ?
Definition :
*Client should not be forced to depend on methods that they don’t use.
*A class should perform only actions that are needed to fulfill its role.
*Do not let interfaces become larger ,divide them into many small interfaces so each one of them perform a specific role.
_______________________________________________
Why it matters :
*This principle aims at sippliting actions into smaller ones so that classes executes ONLY actions required from it.
=>More reusable code
=>Focusing on one aspect
=>Reduce coupling
What is DIP ?
Definition :
*High level modules should not depend on low level modules .Both should depend on the abstraction.
*Abstractions should depend on details. Details should depend on abstraction.
______________________________________________
Keyword definitions:
High level module : Class that use the tool to execute the action.
Low level module : Class of tool needed to execute action.
Abstraction : interface used to connect both classes.
Details : How the tool works.
_______________________________________________
Why it matters : Reduce dependency of high level class on low level class by introducing an interface.
=>Reduce coupling
=>Reusable code
A good Resource for learning 5 SOLID and Programming in general :
https://medium.com/backticks-tildes/the-s-o-l-i-d-principles-in-pictures-b34ce2f1e898
_________________________________________
Also:
https://mmmake.com/en/blog/solid-principles-easily-explained/
Clean Code Summary
See Word Doc