Visitor pattern: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Created Nim solution.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
Line 467:
===Translation of C# example===
As is often the case in practice, the following example departs somewhat from the typical operation of the pattern described above. There is no abstract Visitor class - only a concrete Visitor class - and the 'visit' methods are called something else.
<syntaxhighlight lang="ecmascriptwren">class ExpressionPrintingVisitor {
construct new(){}
 
Line 540:
{{libheader|Wren-str}}
Note that Wren is dynamically typed and can only overload methods based on arity and not on argument type. In the following example, rather than having separate methods for each element type, we instead have a single 'visit' method which tests the type of the argument at run time and takes the appropriate action.
<syntaxhighlight lang="ecmascriptwren">import "./str" for Str
 
// abstract class
9,476

edits