Wednesday 18 July 2007

The Willy Wonka abstract factory

I think for the time being I have said everything I have to say about outsourcing. So now I'll leave this controversial topic and start writing a bit about software patterns. So, if you are not so technically oriented, it will be boring for a while.
One software pattern I find extremely useful is the abstract factory. I think polimorphism is only really useful with abstract factories. However, there is a point where you must chose one (and only one) concrete factory. How do you choose?
One strategy I found useful is to use a map between a key and the constructor or the key and a structure containing the constructor. As you can see, all the constructors or structures are very similar, just like Oompa Loompas, and that's why I call this decission strategy the Willy Wonka.
The advantages is that only declarative code needs to be added to add new classes, so bugs can hardly be introduced

Add to Technorati Favorites

No comments: