Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:26:40+00:00 2026-05-22T17:26:40+00:00

I am considering refactoring an open source project, Afterthought , to make it more

  • 0

I am considering refactoring an open source project, Afterthought, to make it more intuitive to use. The basic idea is that developers creating amendments in Afterthought will be amending a specific .NET type and given the opportunity to modify the type itself, and lists of properties, methods, events, constructors, etc. (the tree). The API’s I use internally Microsoft CCI Metadata make extensive use of the visitor pattern in their API’s, so I adopted a similar approach in Afterthought, as follows:

public override void Amend()
{
    // Amend the type here, add properties, add methods, etc.
}

public override void Amend<TProperty>(Property<TProperty> property)
{
    // Amend properties here
    if (property.Name == "Result")
    {
        // Modify Result property
    }
}

public override void Amend(Method method)
{
    // Amend methods here
    if (method.Name == "Add")
    {
        // Modify Add method
        method.Implement(TInstance instance, int x, int y) => x + y);
    }
}

However, I have discovered that the visitor pattern really ends up redistributing the code solving the target problem (such as instrumenting a class library) into a series of different methods focused on aspects of the tree. This is easy to implement for the developer creating the API, but the consumer must spread their code out in a somewhat unnatural way. So I pose the question, what are the benefits to the vistor-pattern over just exposing the tree as lists and leveraging a LINQ-style approach?

Here is the alternative syntax I am considering:

public override void Amend()
{
    // Do everything here, possibly calling methods just to organize the code

    // Modify Add method
    Methods.Named("Add").WithParams<int, int>()
        .Implement((instance, x, y) => x + y);
}

So in this case, the author of an amendment can write all of the code in one place (or places of their choosing) by interacting with lists that expose a fluent/LINQ API instead of overriding methods. Obviously this approach is slightly less performant (more iterations, etc.), but outside of this, what are the downsides?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:26:41+00:00Added an answer on May 22, 2026 at 5:26 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made an open source release based on a codebase which contained unfinished refactoring
Considering that SQL Server Express is free, why would you ever use any other
Considering this code, can I be absolutely sure that the finally block always executes,
Considering the criteria listed below, which of Python, Groovy or Ruby would you use?
Considering that a processor runs at 100 MHz and the data is coming to
Considering the fact that openmp uses simd model i.e. each instruction is executed by
I am considering releasing one of my class libraries written in C# as open
I have recently joined a small development team that is considering a new version
I am considering refactoring a repository I have to improve its flexibility and reduce
I'm aware that a common performance refactoring is to replace simple for 's by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.