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

No comments:
Post a Comment