the solid principles Flashcards

1
Q

why do we use the solid principles

A

they tell us how to arrange our functions and data structures into classes and how they should interact with eachother

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

source code dependency

A

high level units are dependant on what happens in the lower level units creating a hierarchy and making it harder to identify where a problem originated

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

what do we need in principles of good design

A

reduce coupling and increase cohesion

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

cohesion

A

each unit should be focused on one thing

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

what 3 things should we avoid in good design

A

rigid design
fragile design
immobile design

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

rigid design

A

every change may cause changes in other parts of the system

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

fragile design

A

the system breaks when a single change is made (due to high coupling)

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

immobile design

A

when code cant be reused
the design contains functionality that could be used in another system but the effect and risk of extracting it would be too big

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

srp

A

solid responsibility principle; a module should be responsible for only one actor

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

why is srp a problem (solid responsibility principle)

A

you may need to change the needs for one actor which would then change something for all other actors

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

what is the solution to solid responsibility principle

A

decouple; separate the code for different actors into separate code units

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

ocp

A

open-closed principle; classes should be open for extension but closed for modification

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

what is the benefit of open-closed principle

A

you reduce making errors when you have to make changes

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

what is the solution for open-closed principle

A

the class is changed to an interface and the old methods are turned into concrete classes

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

lsp

A

liskov substitution principle; the child class should inherit all features of the parent class

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

isp

A

interface segregation principle; a client shouldn’t depend/have access to methods that they don’t use

17
Q

what is the issue with not using isp (interface segregation principle)

A

a client may have to be recompiled as a method they weren’t using had to be modified when it shouldn’t have effected them in the first place

18
Q

how do we solve isp (interface segregation principle)

A

polluted interfaces should be split
there should be interfaces between the client and the main class containing only the methods that the client can use

19
Q

dip

A

dependency inversion principle; allows you to have flexible systems where the source code is only dependent on abstractions not concrete implementations

20
Q

why do we use dip (dependency inversion principle)

A

we dont want to be dependent on things that might change

21
Q

what is the solution for dip (dependency inversion principle)

A

create an interface and instead of referring to the concrete name you refer to the interface