Temporary Field

I often see instance variables in an object which are only used while some operation is being performed. For example, if you are trying to send a report to the printer, the printer context might be stored in an instance variable. Rather than storing it in an instance variable, you should try to pass it as a parameter. If you have many variables all used during that same operation, you may be missing an object. Maybe those variables belong to another class. If you create an instance of that class and pass it as a parameter, it can help you do the work. Or better still, maybe that new class will do the operation of generating the report and talk back to your original object in the first place. This will create simpler designs because you don't clutter your objects with unneeded instance variables.

Download