The other day I ran across a blog that showed a good way of cleaning up a mess. Joe Lowrance had a class that did a large amount of validation logic and he decided to separate it out in different classes. After he had, he noticed that it could compose it all as a decorator. His description is very much like Move Embellishment to Decorator in Josh Kerievsky's Refactoring to Patterns. Well worth a look.
If I had to go further with his example, I might move toward using the prototype pattern to create the decorated objects, but prototype is a big gun. I'd hold back until I had a few more cases.
Comments