Detailed visitor pattern (not attached java language source code)

Visitor pattern (Visitor Pattern) :

It represents an operation of each element of an object structure effect. It allows you to define the role of the elements without changing the premise of the new categories of operation of these elements. (Represent an operation to be performedon the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.)

Motivation mode : the object is stored in a set, they may have different types (even if there is a common interface) for the collection of objects, the object can accept a class called visitor to access, different access by its access methods are different.

Development scenarios : (application range is very narrow, you can understand):

  1. XML document parser design;
  2. Compiler design;
  3. Complex collection of objects

If you want to know more design patterns, you can visit: Introduction Overview of design patterns and 23 kinds of design patterns

Guess you like

Origin blog.csdn.net/cui_yonghua/article/details/93462782