Clean Code Flashcards

1
Q

What are Lehman’s two laws?

A

A system that is used will be changed.
An evolving system increases its complexity unless work is done to reduce it.

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

What are the SOLID principles?

A

Single Responsibility
Open Closed
Liskov Substitution
Interface Segregation
Dependency Inversion

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

What does the Single Responsibility principle say?

A

A module should only have a single responsibility
Violation: class Report parses and visualizes report
Solution: split class into Parser and Visualizer

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

What does the Open Closed Principle say?

A

Modify behavior by adding new code, not by changing old code
Violation: JPlag-Gen insert strategy hard coded as part of obfuscation method
Solution: use strategy interface, pass implementation

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

What does the Liskov Substitution principle say?

A

Subclasses must not change behavior of superclass
Violation: subclass Square of Rectangle, setWidth breaks
Solution: interface Shape
Logically: Precondition must be weaker and postcondition stronger

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

What does the Interface Segregation Principle say?

A

Interfaces should be as lean as possible
Violation: broad interface XeroxJob
Solution: Split into PrintJob, StapleJob, …

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

What does the Dependency Inversion principle say?

A

Depend upon abstractions, not implementations
Violation: TextEditor depends on Keyboard
Solution: TextEditor depends on Reader, Keyboard implements Reader

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

What are some other Clean Code principles?

A

Law of Demeter
Boy Scout Rule
Principle of Least Surprise
Coding Conventions
Don’t Repeat Yourself
Keep it simple, stupid
You ain’t gonna need it
Single level of abstraction

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