Archive for the ‘Objects’ category

Classic Singleton

February 28, 2007

February is nearly out and I haven’t posted for a few weeks so I thought I’d just throw in my thoughts on the use and misuse of Singletons! Many of my colleagues working in Java pepper their code with static methods and use them as placeholders for pure function calls. Some would argue that the language encourages this.

I’ve also seen the same thing in Smalltalk code – since the class side only exists once in the image it is in effect a Singleton and therefore we can use this to our advantage and write class methods to achieve the Singleton effect. So if you want to create a WidgetFactory as a Singleton you can simply add class methods to WidgetFactory that return widgets for you (e.g. #getWidget:). But just because you can doesn’t mean you should!

(more…)

Scriptacu-list Tutorial(Part 3)

January 22, 2007

So we’ve got a simple Contact List working but there are two big problems.

  1. When I’m editing the contact the data changes even if I click “Cancel”.
  2. It doesn’t look very pretty.

Today we are going to fix this…

(more…)

A Matter of Factory

January 10, 2007

In my continued exploration of Seaside I revisited an implementation of Factory pattern that is especially easy in Smalltalk and oh so difficult in Java. I enjoyed the rediscovery so much I thought I share it here. (more…)