Weird widget adapter

February 5, 2010

I’m still not really sure what misconception lead to this class:

public class StatusBar {
   private JTextField status;

   public void setStatus (String status) {
      this.status.setText(status);
   }
   public void clearStatus () {
      this.status.setText("");
   }
   public JTextField getStatus () {
      return this.status;
   }
}

I can’t comprehend why they didn’t just extend JTextField to add their methods instead of doing this weird wrapping. This violation of encapsulation principles really hurts somehow.


Not much time

February 5, 2010

I just found this within a sourcecode comment a student team handed in:

Sorry, but we had not much time this week, so our implementation is more or less garbage.

I’m not really sure, if I should look into the sourcecode at all or just take their own assessment…

Addition:

I should have taken their remark for real…they actually did nothing except extracting anonymous classes into explicit ones…


Were we supposed to…

January 19, 2010

Last week my students had to solve a very basic exercise concerning the MVC pattern. After almost one week time to work on that and ask questions a student approached me after I explained the observer pattern in class:

“Were we supposed to use the observer pattern in this exercise?”

I replied with the question how he managed to use MVC pattern without it and he said that his solution works. Well, yes. It works. But there is no way of adding a second, third, … view. And again I ask myself why they do not understand the most basic things…


Keep looping

November 28, 2009

Another funny implementation of the line iterator mentioned before. Those two did not at all understand the concept of lightweight associated with an iterator. Each call of next() or hasNext() resulted in a call of this method:

public String getLineAtPosition (int index) {
    FileInputStream dataFile = new FileInputStream(this.fileName);
    byte[] buffer = new byte[1];
    String data = "";

    while ((dataFile.available() != 0) && (index != 0)) {
        dataFile.read(buffer);
        data += (char) buffer[0];
        if (lineBreak(data)) {
            index--;
            data = "";
        }
    }
    if (dataFile.available() == 0) {
        return "Insufficient data.";
    }
    while (dataFile.available() != 0) {
        dataFile.read(buffer);
        data += (char) buffer[0];
        if (lineBreak(data)) {
            data = noLineBreak(data);
            break;
        }
    }
    return data;
}

Well, there are a lot of grave mistakes in here, too. But imagine this method called every time! A test case reading Goethe’s “Zauberlehrling” (111 lines) took almost a minute to finish…


Not in use

November 28, 2009

This was handed in as an implementation of a class, which allows iterating the lines of a file one by one. Of course, the students were supposed to use the Iterator interface from the Java library.

/**
 * not in use
 */
public boolean hasNext() {
    return false;
}

I wonder if they even bothered to look at the documentation at all.


Follow

Get every new post delivered to your Inbox.