chris clarke
software development that works…or something
Annoying Patterns: Setter Injection
May 2, 2007 on 8:45 pm | In Annoying Patterns | No CommentsWhat do I have to do to get this object to work in the way I want?
Does setting some things rely on having set something else?
With all these public setter methods the objects state can change throughout it’s life. If I have to pass references to this object around maybe I don’t want people changing it’s state.
Annoying Patterns: Saying what you’re about to do
April 18, 2007 on 5:47 pm | In Annoying Patterns | No CommentsThis pattern is best demonstrated with a few examples:
// Send the message
connection.send();
// Start all the servers
for (Server server : serverList) {
server.start();
}
Basically, the comment is describing what you are doing on the next line, and is just not needed.
Sometimes the comments are telling you something, for example:
// Send the message to everyone
connection.send();
Could perhaps be telling you that a method needs to be renamed:
connection.sendTheMessageToEveryone();
Then the comment can be removed and it is clear what the code is doing.
Annoying Patterns: The Hidden ‘On’ Switch
March 15, 2007 on 11:12 pm | In Annoying Patterns | 1 CommentThe hidden ‘on’ switch is a method that you need to call on an object before it starts actually working. Specifically, the object does not make it clear that you need to flick the ‘on’ switch when you start calling methods before turning it ‘on’.
A couple of examples:
javax.jms.Connection:
If you don’t call start() it will appear to be perfectly happy but nothing will happen.
org.apache.tools.ant.Project:
If you don’t call init() it won’t tell you that init() needs to be called, instead it will say something like “Could not create task or type of type: property.”
Possible Solutions?
The JMS one is quite tricky because you want set up all your listeners before you start the connection - dunno. With the ant one, you could put init() code in the Project constructor (duh) or use a flag:
if (! initCalled) {
throw new YouForgotToCallInitYouMoronException("call init() first");
}
Powered by Cheese.
RSS Entries Feed.
RSS Comments Feed
^Top^