Lecture 10-State checking & Feature envy Flashcards
(11 cards)
What is state checking?
-Conditional logic that simulates polymorphism.
-Comes in the form of if/else if OR switch cases
What is feature envy?
When a method is more interested in a class other than the one it belongs to.
What design principle does feature envy violate?
Design principle indicating that behaviour should be allocated along with the data being accessed.
What is the basic rule to follow for feature envy?
-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 to fix feature envy?
-Using the MOVE method
-Using the EXTRACT then MOVE methods –> only a part of a method suffers from feature envy
What are the pros of feature envy? (2)
-Less code duplication
-Better code organization
How is the envied data accessed?
Through a parameter of the method or a field of the class.
What is a data class ?
-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.
What design principle does data class violate?
Design principle indicating that behaviour should be allocated along with the data being accessed.
How to fix data class smell?
-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.
What is the instance checking in OOP?
It involves determining the type of an object at runtime.