Here’s an OO question for everyone who’s reading out there, when do you use
static private methods?
That a method is
private implies that it’s only going to be used within that class; that a method is
static means that it’s operation in now depends on the state of your object instance. For example, in writing lots of CGI type stuff recently, I’ve been doing Ye Old Extract Method on many little things; that is, instead of in-lining logic to, say, build up a log message in a
StringBuffer, I just make a method like
Now, these methods really don’t need to dink around with the instance at all: they get everything they need from the formal parameters. So, you might think, well, this could be a
static method. But is that wise?
The thinking I have here is that if a
private method doesn’t need access to the instance, then I make it
static. Following this thinking, in doing servlet work — where you’re basically doing procedural/static programing in one big ass method — I end up creating a lot of
private static methods, and it looks kind of wierd.