Archives for the 'patterns' Category
FilterQ - A lightweight filtering API for Iterable Objects.
Thursday, July 30th, 2009
Wow, version 0.3 of FilterQ has been released and is available at filterq.googlecode.com. Several cool features have been added, several bugs have been fixed. But the best of all things, at least for me, is that I am using it in my JUnit 4.5 extensions project. FilterQ is my lightweight filtering API for Iterable Objects [...]
More on Filters as First-class functions.
Friday, October 17th, 2008
By expanding (more like enhancing ) the filter pattern described here and borrowing some of the beauties of the matcher pattern in Guice, I coded a more concise version of this filter pattern. Now this pattern’s implementation has a fluent API for combining other filters together, a place where all filters can be defined, [...]
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 [...]
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 [...]
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(){
[...]
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 [...]