Aliasing problems and final member variables

I hit a really stupid problem today, and I’ve only got myself to blame (as usual).

The problem was really simple. I was making an object that needed to know when it was created. This creation date wasn’t necessarily “now”, so I was passing a Calendar object in to the constructor of the object to represent the creation date.

Continue reading “Aliasing problems and final member variables”

Refactoring the “The Two Towers”

For Christmas, I (like many geeks and non-geeks around the world) got a copy of the “The Two Towers” boxed set (the 4 disc one). Should my wife ever read this, thanks again for this present.

Continue reading “Refactoring the “The Two Towers””

Examples for “More on getters and setters”

At the request of a reader, I’ve decided to post some examples on how something like the Employee class described in Allen Holub’s article More on getters and setters could evolve. This may not be the only way, but it certainly is one way.

Continue reading “Examples for “More on getters and setters””

More on “More on getters and setters”

Allen Holub wrote an article in Javaworld recently entitled More on getters and setters Oh boy, has this article caused some fuss in places.

Continue reading “More on “More on getters and setters””

JUnit and data-driven tests

Here’s a technique I sometimes use when I’m doing test-driven development (which is my preferred coding technique). Let’s say I’ve got a bunch of test cases that are all basically the same, but they have slightly different inputs and slightly different outputs. A typical test case might look like this:

Continue reading “JUnit and data-driven tests”