Strategy Pattern vs Decorator Pattern
I am trying to understand the difference between Strategy and Decorator Pattern.
It seems like both are serving the same purpose , in fact decorator pattern is more preferred.
If anybody who can let me understand this,
Sukesh Marla, Nov 06, 2012
This pattern can be used in a scenario where particular property is manipulated on the existing object. It favours composition of objects where one object will be composed in to another of same type and it goes on. For eg. Cost of a Car object can vary depend on its model. In this case, each Car model decorator will have composition of Car object and it will operate on its cost. Top Model -> Basic Model -> Car
Lets say you have some workflow design in visual studio. Suppose if you want to open that design in 2 views.
Design mode view
In this case, "Viewing" is the only one activity that user going to perform, but based on the user's choice the "Strategy" of the viewing will get differ. Suppose if the user selects design view, the strategy is "DesignViewStrategy" and if the user selects code view, then the strategy is "CodeViewStrategy".
So, same activity for the user only the algorithm(Strategy) differs.
Hope the above helps you...
Vivekananda P, Nov 07, 2012