Back to Catalog
Code Smells
Object-Orientation Abusers
Temporary Field
Instance variables that are only used in certain situations.
Intent & Description
'
🎯 Intent
Identify fields that are only used in certain methods or under specific conditions.
📋 Context
You have instance variables that are only set and used in specific methods. This makes the class’s state confusing and hard to understand.
💡 Solution
Extract the methods and their temporary fields into a separate class using Extract Class.'
Real-world Use Case
Use when fields are only used in specific scenarios or methods.
Source
📌 TL;DR
Fields used only in specific scenarios indicate poor class design. Extract into separate classes.