Clean Code Flashcards

1
Q

What is SOLID in clean code ?

A

SOLID are 5 principles introduced by Robert C.Martin (referred to as “Uncle Bob”) to make code more understandable, flexible and easier to maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are 5 SOLID principles ?

A

SRP : Single Responsibility Principle
OCP : Open/Closed Principle
LSP : Liskov Substitution Principle
ISP : Interface Segregation Principle
DIP : Dependency Inversion Principle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is SRP ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is OCP ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is LSP ?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is ISP ?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is DIP ?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A good Resource for learning 5 SOLID and Programming in general :

A

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/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Clean Code Summary

A

See Word Doc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly