terça-feira, 27 de abril de 2010

New pattern - The Match Marker Design Pattern

Yes that is true, the GOF Design Pattern book is not the bible of the OO design patterns; it is just The Book of Genesis, the beginning but it is far away of the end. In fact new problems, causes new common ways to solve them and at a final stage new patterns.

In a recent article Michael Bar-Sinai presents a new pattern The Match Marker Design Pattern, which has the intention to solve similar problems to the Visitor pattern. The main idea of this pattern is to solve the situation where you want to extend the action applied to your business objects in a better and clear way than just extending objects.

Let's suppose this problem (well it is the same one presented by Michael, I guess it is easier to show the same): you have an Employee and needs to calculate the salary of it, as type of Employee we have Manager and Engineer. How to solve this problem? Create a salary calculator that has a method that checks the instance of the class to calculate? Does allow the Employee to return the salary and overwrite it for each class?

Well take a look at this pattern: it is a interesting way to solve the problem: The Match Marker Design Pattern.
For those that want to remember the Visitor pattern, here it goes an article explaining it: Design Patterns Uncovered: The Visitor Pattern.

Enjoy it!

Nenhum comentário: