Temporary field smell

From CSSEMediaWiki
Jump to: navigation, search

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.

See also


Personal tools