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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:21:34+00:00 2026-05-10T14:21:34+00:00

I have heard/read the term but don’t quite understand what it means. When should

  • 0

I have heard/read the term but don’t quite understand what it means.

When should I use this technique and how would I use it? Can anyone provide a good code sample?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T14:21:35+00:00Added an answer on May 10, 2026 at 2:21 pm

    The visitor pattern is a way of doing double-dispatch in an object-oriented way.

    It’s useful for when you want to choose which method to use for a given argument based on its type at runtime rather than compile time.

    Double dispatch is a special case of multiple dispatch.

    When you call a virtual method on an object, that’s considered single-dispatch because which actual method is called depends on the type of the single object.

    For double dispatch, both the object’s type and the method sole argument’s type is taken into account. This is like method overload resolution, except that the argument type is determined at runtime in double-dispatch instead of statically at compile-time.

    In multiple-dispatch, a method can have multiple arguments passed to it and which implementation is used depends on each argument’s type. The order that the types are evaluated depends on the language. In LISP, it checks each type from first to last.

    Languages with multiple dispatch make use of generic functions, which are just function delcarations and aren’t like generic methods, which use type parameters.

    To do double-dispatch in C#, you can declare a method with a sole object argument and then specific methods with specific types:

    using System.Linq;    class DoubleDispatch {      public T Foo<T>(object arg)     {          var method = from m in GetType().GetMethods()                    where    m.Name == 'Foo'                           && m.GetParameters().Length==1                          && arg.GetType().IsAssignableFrom                                            (m.GetParameters()[0].GetType())                          && m.ReturnType == typeof(T)                    select m;          return (T) method.Single().Invoke(this,new object[]{arg});               }      public int Foo(int arg) { /* ... */ }      static void Test()      {          object x = 5;         Foo<int>(x); //should call Foo(int) via Foo<T>(object).     } }        
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have heard a lot about anti patterns and would like to read a
I have heard that 'better-fit' is pretty commonly used, but I don't seem to
According to Wikipedia, x86 is a CISC design, but I also have heard/read that
I've read every other thread on this and have tried everything but the Build
I have occasionally heard or read about people asserting their interfaces in a unit
I have heard that web-based chat clients tend to use networking frameworks such as
I have heard and read that a string can not be changed (immutable?). That
According to this Wikipedia article on Google App Engine : Developers have read-only access
I have heard and read about flip-flops with regular expressions in Perl and Ruby
I have heard that when dealing with mutexes, the necessary memory barriers are handled

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.