Archives for May, 2008

Documenting Exceptions via Factory Methods

Wednesday, May 28th, 2008

Jesse described a technique for handling methods that always throws. This is a very interesting technique. Having written that, would it not be nice to encourage the use of this technique, in our Java coding conventions, as a way to document DRY exceptions? Honestly, I’d’ think we should. It would prevent us from repeating the [...]

programming, random ideas | No Comments

Do you need to cache your objects?

Wednesday, May 14th, 2008

I’ve found the Cache Management Pattern very useful in more than a couple of projects that needed a simple caching mechanism. Now that we have Generics at our disposal, I think this pattern deserves a tiny change. Something like a generic structure or code that we can follow or use every time we need to [...]

patterns, programming | No Comments

DRY benchmarking….

Tuesday, May 13th, 2008

Every time we try to write a benchmark for particular functionality, we habitually specify a load (max iterations), write a for-loop, set timers before and after the loop, and call the method of interest inside this loop. This typically involves copying & pasting from another benchmark and adapting the current benchmark to your needs. Why [...]

patterns, programming | No Comments

No more downcasting via “Recursive Bounds”

Sunday, May 4th, 2008

I recently coded a fairly tiny application that made use of the MVC pattern. One of the things that I noticed while I was writing it was that I was down-casting a lot. Imagine something like this:
Example

// main type
interface Model {
void someMethod();
}

// implementation
class Mixer implements Model {
public void anotherMethod(){
[...]

patterns, programming | No Comments

A pattern for using EasyMock…

Saturday, May 3rd, 2008

Ralf Stuckert wrote a great article on EasyMock titled "Getting started with EasyMock2."  He clearly defined a pattern for using this library.
The pattern is

Create a mock.

Set up your expectations.

Set the mock to replay mode.

Call your code under test.

Verify that your expectations have been met.

Believe me, knowing this pattern will save you a lot [...]

patterns | No Comments

 

May 2008
M T W T F S S
« Apr   Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

Archives

Tags