I've heard that variables should be declared as close to the point that they're used as possible. However, I've also heard that member variables should be used to describe something that is a characteristic of a class.
I find that these two pieces of advice sometimes conflict. For example, say I have a class the parses JSON using the jackson library. Would the jackson parser object I create in order for the class to be able to parse JSON be considered a "characteristic" of the class? Without the parser object my class can't do what it was designed to do.
However, I only really use the parser object in my main parsing function-- as such, I could just create a local version there rather than giving it class wide scope.
Perhaps that example was a bit contrived, but hopefully it conveys the gist of my question. What exactly constitutes a "characteristic" of a class?
car
object from aCar
class, but it doesn't make sense to create multiplejsonParsers
from aJsonParser
class. They're not things - parsing is something you do.