score:3
The Visitor pattern helps you to avoid creating if
or switch
statements that will test the type of the visited element. The avoidance of these statements is generally considered as a good practice. If the operation you implement does not differentiate between various possible types of elements that can be visited, then, yes, the visitor pattern does not bring you any advantage over your alternative approach any other approach.
The problem is maybe in the understanding of the Visitor pattern: it is mainly about implementing the double-dispatch in languages that does not offer this feature, or (this is the case of C#) where the usage double-dispatch brings considerable performance issues. It is not about tree traversing. It can be even used for classes that does not form a hierarchical structure. The GoF book says that the traversing algorithm may be implemented either by the Visitor itself, either by the visited elements, or even either by the client.
Edit: I read you question again carefully, I think that your approach is, let's say, an alternative implementation of the Visitor pattern, where the Visitor is not a class, but set of lambda functions.
Source: stackoverflow.com
Related Articles
- Visitor Pattern versus LINQ-style fluent syntax for tree traversal API
- Syntax to execute code block inside Linq query?
- LINQ Source Code Available
- Nested GroupBy LINQ Using Fluent Syntax
- creating Linq to sqlite dbml from DbLinq source code
- Linq sub query when using a repository pattern with EF code first
- Can I mix LINQ and Fluent Syntax in EF Core?
- Converting LINQ statement from query to fluent c# syntax
- How I change this code to be in linq style
- source code for LINQ 101 samples
- Converting SQL query to LINQ or LINQ fluent Syntax
- LINQ method syntax style
- Create a tree structure in linq with a single list source with parent - child as strings of an object
- Linq Projecting from one type to a second using fluent syntax
- C# Lambda Method syntax to obtain attribute values that match pattern in LINQ to XML
- LINQ Fluent Syntax - Deselecting Items in Array
- c# Linq or code to extract groups from a single list of source data
- Add TPT Inherited Code First Model to Linq Fluent API
- Duplicate results with GroupBy using Linq Query Expression but not using Fluent Syntax
- Linq - how to loop a tree data structure to build a tree style object
- Convert string[] to int[] in one line of code using LINQ
- Linq style "For Each"
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ OrderBy versus ThenBy
- Linq Syntax - Selecting multiple columns
- Linq code to select one item
- Using LINQ extension method syntax on a MatchCollection
- Is there a C# LINQ syntax for the Queryable.SelectMany() method?
- Searching a tree using LINQ
- LINQ - Query syntax vs method chains & lambda
- How to print the values not the object IEnumerable<IEnumerable<>()>()
- HTML Agility Pack and LINQ
- How to use "Group by" LINQ?
- C# MVC strongly typed view with ViewModel
- Date comparision using Linq
- How to get list<string> from list of list of list linq C#
- Let the SequenceEqual Work for the list
- Northwind database JOIN QUERY between three tables (many to many)
- merging 2 collections and find all the unique items
- concatenate strings in LINQ query
- I Need to insert Exception details into sql server database
- Convert DataTable to String Array through Extension Method
- LINQ method How to SelectMany with additional column from Parent class
- LINQ query with distinct count
- Using LINQ Group By to return new XElements
- EF 4.1 / Linq-to-SQL: What is better: using Equals or ==?
- How to Select/Iterate through multiple elements with a specific attribute XML?
- LINQ - LEFT OUTER JOIN with parameter
- How can I select the first child of a child using linq?
- Linq to SQL any from Enumerable