Temporary field smell

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
JaninaVoigt (Talk | contribs)
(New page: This smell occurs when a class has a field that is only used some of the time. A class like this can be hard to understand because you would normally expect it to use all its instance vari...)
Newer edit →

Revision as of 05:31, 31 July 2009

This smell occurs when a class has a field that is only used some of the time. A class like this can be hard to understand because you would normally expect it to use all its instance variables and it can be difficult to see what the temporary variable is used for.

This can for example happen when you have an algorithm that requires data structures for several methods and because you don't want to pass the data structures around as parameters you make them instance variables. However, they only have a valid value during the algorithm's execution. Instead, you should Extract Class to make a class containing the algorithm, the data structures and the methods that use the data structures.