I am not seeing any difference. Looks like both Patterns are trying to compose objects. Can anyone explain the intentions behind these two patterns?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are different patterns, but they are often used together.
The point of composite is to apply the same operation to a bunch of elements that share an interface. The point of visitor is to extend a bunch of elements with a new operation without changing their implementation nor the caller’s implementation. Therefore you often see:
This way you can keep the implementation of the composite and the classes that are in the composite static, and only vary the kind of Visitor you apply to them.