Design Patterns Visitor Pattern - Design Patterns

What is Design Patterns Visitor Pattern?

In Visitor pattern, we use a visitor class which modify the execute algorithm of a constituent class. By this way, effecting algorithm of part can vary as and when visitor varies. This pattern comes under behaviour pattern category. As per the pattern, element object has to recognize the visitor object so that visitor object handles the process on the element object.


We are going to generate a Computer Part interface defining understand opearation.Keyboard, Mouse, Monitor and Computer are concrete classes implementing Computer Part interface. We will classify another interface ComputerPartVisitor which will define visitor class operations. Computerises concrete visitor to do consequent action.

VisitorPatternDemo, our demo class, will use Computer and ComputerPartVisitor classes to display use of visitor pattern.

Step 1

Define an interface to represent element.

Step 2

Make concrete classes extending the above class.

Step 3

Describe an interface to represent visitor.

Step 4

Form concrete company implementing the above class.

Step 5

Use the ComputerPartDisplayVisitor to present parts of processor.

Step 6

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Design Patterns Topics