this.setDraft(false) or this.post()

11 May 2006, 07:26

I’m doing a lot of Swing lately and there is something that irritates me even harder as people who drive in the middle lane all the time:

setEnabled(false)

This method is defined on the JComponent class so it gets used a lot. It irritates me a lot. How setLogical(false) does this sound? Imagine having to turn off the engine of your car with car.setEngineRunning(false)!

It’s hard to read and it implies changing a property of an object, when instead you are changing the behavior of an object. Of course, difference in behavior of objects is often if not always determined by the value(s) of one or more properties of that object, but I shouldn’t have to know about that. That’s up to the implementation of the object!

Doesn’t this sound better?
setDisabled()

Or even better:
disable()

Now I’m just sending a message to an object saying: dude, disable yourself, I don’t care how, just do it.

Funny thing is that those methods (enable() and disable()) do exist, but they are already deprecated since JDK 1.1 and replaced by setEnabled(boolean). I wonder why that is?

A related but not entirely the same post by Kevin Rutherford, which made me think about this more consciously: avoid boolean parameters

{ tags: }

2 Comments for this.setDraft(false) or this.post()

Multiple bounds in Java 5 generics Last post