Software Design

Visitor Pattern: Exporting Document AST Nodes

UML Class Diagrams · made in Skemio

UML class diagram demonstrating the Visitor pattern with Node elements (Heading, Paragraph) accepting a DocumentVisitor interface implemented by HtmlExportVisitor.
UML class diagram demonstrating the Visitor pattern with Node elements (Heading, Paragraph) accepting a DocumentVisitor interface implemented by HtmlExportVisitor.

What it shows

  • Separates document data structures from the operations performed on them.
  • Adds new export targets (Markdown, HTML, PDF) without touching node classes.
  • Uses double dispatch via accept(visitor) to resolve the exact method call.

The takeaway

Use the Visitor pattern when your data structure is stable but operations change often.

More uml class diagrams