Lecture 10-State checking & Feature envy Flashcards

1
Q

What is state checking?

A

-Conditional logic that simulates polymorphism.
-Comes in the form of if/else if OR switch cases

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

What is feature envy?

A

When a method is more interested in a class other than the one it belongs to.

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

What design principle does feature envy violate?

A

Design principle indicating that behaviour should be allocated along with the data being accessed.

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

What is the basic rule to follow for feature envy?

A

-If things change at the same time, you should keep them in the same place.
-Usually data and functions that use this data are changed together.

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

How to fix feature envy?

A

-Using the MOVE method
-Using the EXTRACT then MOVE methods –> only a part of a method suffers from feature envy

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

What are the pros of feature envy? (2)

A

-Less code duplication
-Better code organization

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

How is the envied data accessed?

A

Through a parameter of the method or a field of the class.

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

What is a data class ?

A

-A class containing mostly attributes and VERY FEW OR NO methods accessing them(getters and setters).
-They are containers for data used by other classes.
-Can’t independently operate on the data that they own.

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

What design principle does data class violate?

A

Design principle indicating that behaviour should be allocated along with the data being accessed.

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

How to fix data class smell?

A

-If class has public fields , use Encapsulate field to hide them from direct access AND CAN ONLY BE ACCESSED VIA GETTERS AND SETTERS ONLY.
-If client code that uses the class would be better located in data class, use MOVE and EXTRACT methods to migrate functionality to the data class.

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

What is the instance checking in OOP?

A

It involves determining the type of an object at runtime.

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