Definition
A behavioral pattern which lets you define new methods to a class hierarchy without changing the class hierarchy on which it operates
Applicability
1. When the primary class hierarchy is fixed or it is coming from a different vendor and you cannot make any changes to that hierarchy
2. Several different operations have to be performed on all or some of the classes in the hierarchy
Visitor and Composite Pattern normally go hand in hand together. First, we will try to create an example of composite pattern. A composite pattern is a structural pattern which helps to create tree like hierarchial structures. Consider a linux filesystem where every element is considered as a file. We are trying to achieve the same tree structure using
Directory
, File
and Link
elements. All of these classes implement the interface FileSystemElement
Read more ...