Tuesday, October 19, 2010

Mistake in Wikipedia article on the Builder pattern

The following article on the Builder Design Pattern on Wikipedia, is sort of OK, except that the Java example provided is inaccurate.

The abstract PizzaBuilder class uses abstract functions. That's not really recommended - if you subclass this then it means that you have to implement all the functions. But really, the pattern is meant to be more flexible than that - if you don't want to use the function then you shouldn't have to use it. Therefore, as the Gang of Four say in their book on page 101, the build methods should be left intentionally empty and not declared as abstract functions, "letting clients override only the operations they are interested in".

No comments:

Post a Comment