HeadlinesBriefing favicon HeadlinesBriefing.com

Extensible Visitor Pattern: Solving the Expression Problem

DEV Community •
×

Researchers from Brown University tackled the long‑standing expression problem by proposing an extensible visitor pattern that merges the classic visitor with the factory method. The paper demonstrates how to add new shapes or tools without touching existing code, a core goal of the Open/Closed Principle in practice today.

Implementation samples span four styles: a pure functional version, an interpreter‑based design, a traditional visitor, and the proposed extensible visitor. The author rewrote the examples in C# and F#, exposing recursive shape types like TranslatedShape and UnionShape that challenge conventional visitor recursion for runtime analysis and testing efficiency.

Key insight: recursive visitors must create new visitor instances via a virtual factory method, otherwise nested shapes lose support for new types. The paper’s UnionContainsPoint override demonstrates how to preserve double dispatch, a subtle flaw that standard visitor implementations overlook when handling recursive structures in production systems today.

Practitioners can adopt the extensible visitor to evolve domain models without breaking clients, especially in graphics or CAD libraries where shape hierarchies grow. The accompanying GitHub repo offers ready‑to‑run C# code, enabling teams to benchmark performance against the classic visitor and assess maintenance trade‑offs for modern applications today.