O'Reilly logo

.NET Design Patterns by Shine Xavier, Praseed Pai

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Visitor pattern for document traversal

The tree-structured DOM created by us needs to be traversed to produce the content in an output format like HTML, PDF, or SVG.

Note

The composite tree created by us can be traversed using the GoF visitor pattern. Wherever composite pattern is used for composing an hierarchy of objects, the visitor pattern is a natural choice for the traversal of the tree.

In a visitor pattern implementation, every node in the composite tree will support a method called accept, which takes a visitor concrete class as a parameter. The job of the accept routine is to reflect the call to the appropriate visit method in the visitor concrete class. We declare an interface named IDocumentVisitor with methods for visiting each of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required