DailyWTF: Is That OK?
rl 17:34, 20 Jan 2006 (GMT)
This one's left over from Sculpteur, and the author has wisely neglected to omit his name from the source (although a look through the CVS history would no doubt reveal the culprit).
As any good software developer knows, response codes are an important part of good modular code design, as they allow other modules or program parts to determine whether the module that it called was able to do what was requested or not. Whoever designed this code obviously took this to heart, and since they were using Java, which is of course an object-orientated language, decided to use an object to pass the response code back to the caller.
package uk.ac.soton.itinnovation.sculpteur.webapp.conceptbrowser;
import java.io.*;
public class OServletResponseCode implements Serializable{
public static final OServletResponseCode OK = new OServletResponseCode("OK");
public static final OServletResponseCode ERROR = new OServletResponseCode("ERROR");
private String responseCode = null;
private OServletResponseCode(String responseCode){
this.responseCode = responseCode;
}
public String toString(){
return responseCode;
}
public boolean equals(Object object){
boolean equals = false;
OServletResponseCode responseCode = null;
if(object == null){
return false;
}
if(object instanceof OServletResponseCode == false){
return false;
}
responseCode = (OServletResponseCode)object;
if(!responseCode.toString().equals(this.responseCode)){
return false;
}
return true;
}
}
If we're feeling charitable, you may say "well, perhaps they wanted to return some data along with the response code?". Alas, it appears not. The only response codes that are returned are essentially "OK" or "ERROR". I can only assume that using Strings were considered too generic a type by our developer, as Strings can have any number of different values and he wanted only two. The fact that the Boolean values true and false also number two seems to have eluded him.
Personally though, my favourite part is the way that the constants OK and ERROR in the code are assigned not to the Strings "OK" and "ERROR", as one might suspect, but to objects that wrap these strings. Now that's object-orientated coding at its most pure!
Comments[edit]
No comments yet.