Commonalities:
- Strategy, Template method and Visitor : All three patterns are categorized as behavioural patterns.
Differences:
- Template method uses Inheritance and Strategy uses composition
- The Template method implemented by the base class should not be overridden. In this way, the structure of the algorithm is controlled by the super class, and the details are implemented in the sub classes
- Strategy encapsulates the algorithm behind an interface, which provide us ability to change the algorithm at run time
- Visitor pattern is used to perform an operation on a group of similar kind of Objects. With the help of visitor pattern, we can move the operational logic from the objects to another class
- If there is a change in implementation of Operation, we have to just change Visitor class instead of touching all other objects.
Have a look at Template method , Strategy and Visitor and Sourcemaking articles for better understanding.
Related posts:
When should I use the Visitor Design Pattern?
Real World Example of the Strategy Pattern
Template design pattern in JDK, could not find a method defining set of methods to be executed in order