Refactoring & Code Smells Flashcards

1
Q

Define the term refactoring?

A

The main purpose of refactoring is to fight technical debt. It transforms a mess into clean code and simple design.

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

When should you refactor your code?

A

When adding a feature, when fixing a bug or during a code review.

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

When should you NOT refactor your code?

A

If the code need a complete rewrite or there is not enough time to refactor

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

Define the term code smell?

A

A code smell is a surface indication that corresponds to deeper problem in the system.

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

What are some code smells?

A

Bloaters

Object-Orientation Abusers

Change Preventers

Dispensables

Couplers

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

What is a data clump? How should you refactor your code if you find one?

A

It’s a name given to any group of variables which are passed around together throughout various parts of the program.

You should move the code into their own class or passing the entire data object to the method of individual fields.

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

What is feature envy and what should you do about it?

A

A method access the data of another object more than its own data.

Move the method or a part of the method to another place or split the method apart to placed in different classes

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

If a class has several methods which contain conditionals(if/else or switch) blocks that a “type” attribute, what should you do about it?

A

Create subclasses matching the branches of the conditional. In them, create a shared method and move code from the corresponding branch of the conditional to it. Then replace the conditional with the relevant method call. (Polymorphism)

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