Practical questions about using the visitor mode (consult)

Source: Internet
Author: User

On the homepage, I hope more friends can help me. On the other hand, I think this case is typical. If you (especially Dudu) think it is inappropriate, please let me know and I will remove it.

Background: traverses a graph (composed of several elements, each of which is called a shape and connected by connector) to generate an XML file. Each element generates an XMLCode. Looking at the background, this is a typical case of external collection methods. It is also appropriate to use the visitor mode.
Implementation status: In the visitor mode (see figure), objectstructure is responsible for traversing all shapes (you don't have to worry about connector, and another class is responsible for assembling objectstructure, which is assumed to be able to traverse smoothly ). Visitor contains an xmlelement to collect data from various shapes.
Problem: Visitor assigns an ID for a shape each time it accesses it. There is a special shape, which requires the ID of its next shape as its own property (nextshapeid ). That is to say, we need to first access its nextshape (an ID will be assigned to this shape at this time), and then take the ID of the next shape as its own attribute (note that this ID is dynamically generated) to generate your own XML code. There is a conflict between the visitor loop and the objectstructure loop, which are not controlled by the visit, but the traversal policy needs to be changed temporarily when visit is a special shape.
You can help me find a solution that is not bound to vistor.

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.