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 8955051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:27:23+00:00 2026-06-15T14:27:23+00:00

Is there any significant benefit to using either technique? In case there are variations,

  • 0

Is there any significant benefit to using either technique? In case there are variations, the Visitor Pattern I mean is this: http://en.wikipedia.org/wiki/Visitor_pattern

And below is an example of using a delegate to achieve the same effect (at least I think it is the same)

Say there is a collection of nested elements: Schools contain Departments which contain Students

Instead of using the Visitor pattern to perform something on each collection item, why not use a simple callback (Action delegate in C#)

Say something like this

class Department
{
    List Students;
}

class School
{
    List Departments;

    VisitStudents(Action<Student> actionDelegate)
    {
        foreach(var dep in this.Departments)
        {
            foreach(var stu in dep.Students)
            {
                actionDelegate(stu);
            }
        }
    }
}

School A = new School();
...//populate collections

A.Visit((student)=> { ...Do Something with student... });

*EDIT Example with delegate accepting multiple params

Say I wanted to pass both the student and department, I could modify the Action definition like so:
Action

class School
{
    List Departments;

    VisitStudents(Action<Student, Department> actionDelegate, Action<Department> d2)
    {
        foreach(var dep in this.Departments)
        {
            d2(dep); //This performs a different process.
            //Using Visitor pattern would avoid having to keep adding new delegates.
            //This looks like the main benefit so far 
            foreach(var stu in dep.Students)
            {
                actionDelegate(stu, dep);
            }
        }
    }
}
  • 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-06-15T14:27:24+00:00Added an answer on June 15, 2026 at 2:27 pm

    The visitor pattern is usually used when there are more than one type of things that are visited. You have only one type (Students), so you don’t really need the visitor pattern and can just pass in a delegate instance.

    Assume you’d want to visit both Departments and Students. Then you visitor would look like this:

    interface ISchoolVisitor
    {
        void Visit(Department department);
        void Visit(Student student);
    }
    

    Of course, you could also use delegates here as well, but it would be cumbersome to pass in multiple delegate instances — in particular if you have more than 2 types of visited things.

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

Sidebar

Related Questions

Besides readability is there any significant benifit to using a CASE WHEN statement vs
Is there any significant benefit of using schema 1.1 over 1.0?
Assuming a 64-bit JVM, is there any significant benefit to keeping MaxPermSize small? This
Are there any significant reasons for using typeof variable === 'function' versus !!variable.call for
http://lesscss.org/ Yeah the language syntax looks cool, but are there any significant advantages? Because
i was wondering if there is any significant difference between consuming .asmx services with
Possible Duplicate: Is it okay to use array[key] in PHP? Is there any significant
In JSF 2.0, is there any significant technical difference between doing a non-AJAX submit
Are there any significant updates in the Logging facility provided by Java SE 5
Is there any significant performance problems between the two code snippets ? User user

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.