Originally posted by Vijay Kashyap:
Can somebody explain with a simple example the basic difference between these two? I did a google and bit confused with all the different explanation.
The difference is a little bit subtle, and more in the intention than in structure.
Command encapsulates a single action. It therefore tends to have a single method with a rather generic signature. It often is intended to be stored for a longer time and to be executed later - or it is used to provide undo functionality (in which case it will have at least two methods, of course).
Strategy, in contrasst, is used to customize an algorithm. A strategy might have a number of methods specific to the algorithm. Most often strategies will be instanciated immediately before executing the algorithm, and discarded afterwards.
I have to admit, though, that there are cases where I can't tell for sure whether something is a Command or a Strategy. It's not always that important, anyway...
Also can somebody send me the links to good Design Pattern resource(preferably with Java examples).
http://faq.javaranch.com/view?DesignPatternFaq
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus