Visitor mode in Design Mode

Source: Internet
Author: User

1. Visitor mode definition:

Indicates an operation that acts on each element in an object structure. It allows you to define new operations acting on these elements without modifying the element classes, that is, to dynamically add new methods.

Ii. Structure of the Visitor mode:


Iii. Main roles in Visitor mode:
1) Visitor role (Visitor): provides an access operation interface for specific elements in the object structure (ObjectStructure. The operation interface name and parameters identify the specific element role to be accessed. In this way, the visitor can directly access the element through a specific interface of the element role.
2) specific visitor role (ConcreteVisitor): Implements operations on the Vistor interface.
3) Element: this interface defines an accept operation to accept specific visitors.
4) A specific Element role (ConcreteElement): implements the accept operation on the Element.
5) object structure Role (ObjectStructure): A required role in the visitor mode. It must have the following features: it can enumerate its elements; it can provide a high-level interface to allow the visitor to access its elements; it can be a combination (combination mode) or a set, such as a list or an unordered set.

Iv. Advantages and disadvantages of the Visitor mode:
1) Advantage: You can add new operations without modifying specific element classes. The accept method of the element class is used to accept a visitor object.
2) Disadvantages: it is not easy to add element classes frequently. If no element class is added, you must write a method for this element in the Visitor interface and modify the subclass of Visitor.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.