---
# System prepended metadata

title: SOLID

---

# SOLID
Sources:
[Uncle Bob Presentation 1](https://www.youtube.com/watch?v=zHiWqnTWsn4)
[Uncle Bob Presentation 2](https://www.youtube.com/watch?v=t86v3N4OshQ)
[SOLID in 8min](https://www.youtube.com/watch?v=yxf2spbpTSw)
[Five principles of OO](https://www.youtube.com/watch?v=HyQlCMU_Ylw&t)

## Single responsability principle

**a class should only have one reason to change**

don't put functions that would change for different reasons in the same class


## Open/Closed principle

**modules should be open for extension (be extensible) but closed for modification**  
you shouldn't have to rewrite any of it when adding a new feature

**not rigid**: when you add new stuff theres minimal or no recompilation of the overall project at alll

**not fragile**: when you add new stuff you dont have to go hunting for ifs and switched that will need to have that new case written

high level policy does not know about low level details


## Liskov substitution principle

**subclasses must be substitutable for their base class**  
or  
derived classes must be usable through the base class interface, without the need for the user to know the difference

square is a type of rectangle, but this doesnt mean you should make a square and iheret it from rectangle, since they don't share that much in commom ON CODE
(squares have one varible (size) rectangles have two (width, height), therefor all methods also change)


## Interface segregation principle

**the dependency of one class to another should depend on the smallest possible interface**

instead of one fat interface, many small interfaces are preferred. clients should not be forced to implement interfaces they don't use


## Dependency inversion principle

**depend upon abstractions (interfaces) not upon concrete classes**