I got a quick chance to speak with Paul Wheaton about few things the other day, including his old article on the evil of design patterns. Like the article, design patterns will never get too old to be useful; just make sure you're using them effectively.
- Posted by: Cameron McKenzie
- Posted on: July 14 2010 11:23 EDT
I've been on a few projects where everyone was looking for a problem to throw a pattern at. In one particular project a visitor pattern (which is brilliant when well used) was used when all that was needed was just the stock standard template pattern (or simply known as clear and obvious polymorphism in the pre pattern days). It created many problems (including a performance one) and required extra classes to be maintained.
Talking about the visitor pattern, back in 1993 I wrote a tokenizer/parser for importing C++ files into a visual object oriented design tool. After parsing a tree of nodes representing the class' structure was created in memory. Each node had a 'visit' method and what I called a 'Beaver' was told to 'visit' the top node in the tree which then passed it on to the visit method of each of its children and so on. I called it a Beaver because its actions resembled a beaver navigating through the maze of canals and nooks in their habitat.
We used to call this pattern the 'Beaver' until the GoF came along and renamed it the 'Visitor pattern'. All I can say is:
Hmmmm, nice beaver!