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.