Skip to content

Add Visitor pattern#125

Open
SeanTAllen wants to merge 1 commit intomainfrom
visitor-pattern
Open

Add Visitor pattern#125
SeanTAllen wants to merge 1 commit intomainfrom
visitor-pattern

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

The Visitor pattern is a Gang of Four staple that separates traversal from processing. Pony's structural typing makes it lighter than the traditional double-dispatch version, but the core idea is just as useful.

Uses a simplified document renderer as the running example, with ponylang/templates referenced as a real-world exemplar in the discussion. Also broadens the Behavioral Patterns category description and adds a cross-reference from the Notifier pattern page.

The Visitor pattern is a Gang of Four staple that separates traversal
from processing. Pony's structural typing makes it lighter than the
traditional double-dispatch version, but the core idea is just as
useful. Uses a simplified document renderer as the running example,
with ponylang/templates referenced as a real-world exemplar in the
discussion.
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Mar 15, 2026
@SeanTAllen
Copy link
Copy Markdown
Member Author

Rename sinks to visitors.

Pull the "what to do with each segment" part out into an interface. The walker calls the interface; different implementations decide what happens with each piece.

```pony
interface ref DocumentSink
Copy link
Copy Markdown
Member

@jemc jemc Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion to replace Sink term with Visitor (throughout the pattern text)

@SeanTAllen
Copy link
Copy Markdown
Member Author

also comment on the closed world nature of and how that plays into this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discuss during sync Should be discussed during an upcoming sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants