|
This post originated from an RSS feed registered with Agile Buzz
by Joe Walnes.
|
Original Post: OT2004 : Elegant Implementation of Null Objects
Feed Title: Joe's New Jelly
Feed URL: http://joe.truemesh.com/blog/index.rdf
Feed Description: The musings of a ThoughtWorker obsessed with Agile, XP, maintainability, Java, .NET, Ruby and OpenSource. Mmm'kay?
|
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Joe Walnes
Latest Posts From Joe's New Jelly
|
|
Since Dan and I have both been working together again (2 years at ThoughtWorks) and since I moved into a house less than ten minutes walk from his, we very rarely see each other. So it was good fun to have a geeky catch up session and play with some code.
Something Dan showed me:
interface Something {
Something NULL = (Something)Null.object(Something.class);
// more stuff...
}
The Null class is a simple dynamic proxy that will return an immutable null object that does nothing. Methods that return values will return default primitives (0, false), empty arrays or more dynamic proxies.
So at any point in the code you can call Something.NULL to get the null implementation.
Nice! (Dan, upload it somewhere!)
Read: OT2004 : Elegant Implementation of Null Objects