chapter 6 Flashcards

1
Q

what is refactoring?

A

is the process of changing sw in away that:
- doesn’t change external behavior
- but internal structure is improved

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

__________ is the art of improving the art of an existing code [ cleaning up ]?

A

refactoring

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

what are bad smells?

A

problem areas due to poor coding and design choices

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

why should we refactor?

A

RR II HH P
- reduce redundant code
- reduce complexity
- improves design [ prevents “Decay” ]
- improves code readability
- helps code run faster
- helps find bugs
- provides a more expressive internal structure

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

which bad smell is due to too many lines of code, or too many parameters?

A

long method

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

explain a long class bad smell?

A
  • classes do too much
  • reduced cohesion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

explain a divergent change bad smell?

A
  • changes require changes in various d/t subsets of methods
  • multiple changes are made to a single class
  • weak cohesion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

which bad smell is the result of a method requiring lots of info from another class?

A

feature envy

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

explain a lazy class bad smell?

A
  • class isn’t doing enough to justify its existence
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

explain a switch case bad smell?

A
  • result in duplicate codes
  • can be replaced with polymorphism for a more effective approach
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

explain a shotgun surgery bad smell?

A

a single change requires changes to be made to multiple classes simultaneously

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

what is the opposite of shotgun surgery?

A

divergent change

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

explain a data clump bad smell?

A

is a result of multiple attributes clumped together but not belonging to the same class

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

explain a parallel inheritance hierarchy bad smell?

A

addition of a subclass to a hierarchy tree requires similar additions in related hierarchies

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

which bad smell is often used as a deodorant for bad code?

A

comments

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

explain a middle man bad smell?

A

a class delegates many of its responsibilities another class

17
Q

describe a temporary field bad smell

A

is an attribute [ variable ] of an object that is not really needed or is used in limited circumstances.

18
Q

describe a message chain bad smell

A

occurs when a class is highly coupled with other classes in a chain like delegation
[ client asks obj for another obj and so on ]

19
Q

describe a data class bad smell

A

these are classes that do not define methods besides generic getters and setters

20
Q

what are the requirements for refactoring?

A

CPR CCT S
- collective code ownership
- pair programing
- rested programmers
- coding standard
- continuous integration
- tests
- simple design

21
Q

when should you refactor?

A

AAC3FL
- all the time
- when you add new features
- when the code smells
- rule of 3
- when you fix a bug
- when you learn something new

22
Q

when should you not refactor?

A
  • when the tests are failing
  • when you should just rewrite the code
  • when you have a deadline
23
Q

what are obstacles when refactoring?

A

TMCPE - too much pressure
- time pressure - ref takes time
- management issues - “ we pay you to add new features not ref “
- complexity
- performance issues - ref slows down execution
- error possibilities

24
Q

why are programers avoidant to refactoring?

A

LSNF - loser senef
- lack of refactoring skills
- short term focus
- not paid for overhead tasks like ref
- fear of breaking code

25
Q

what refactoring methods can be used in the case of : duplicated code?

A
  • extract method
  • extract class
  • pull up the method
  • form template method
26
Q

what refactoring methods can be used in the case of : data clumps?

A
  • extract class
  • introduce parameter obj
  • preserve whole object
27
Q

what refactoring methods can be used in the case of : long method?

A
  • decompose conditional
  • extract method
  • replace temp with query
  • replace method with method object
28
Q

what refactoring methods can be used in the case of : long parameter list?

A
  • replace parameter with method
  • preserve whole object
  • introduce parameter object
29
Q

what refactoring methods can be used in the case of : middle man?

A
  • hide middleman
  • inline method
  • replace delegation with inheritance
30
Q

what refactoring methods can be used in the case of : shotgun surgery?

A
  • inline class
  • move method
  • move field
31
Q

what refactoring methods can be used in the case of :

A
  • replace conditionals with polymorphism
  • replace type code with subclass
  • replace type code with state
  • replace parameters with explicit methods
  • introduce null objects