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

  • Home
  • SEARCH
  • 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 7694355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:18:03+00:00 2026-05-31T21:18:03+00:00

What is the difference between Double Dispatch and the Visitor Pattern?

  • 0

What is the difference between Double Dispatch and the Visitor Pattern?

  • 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-31T21:18:04+00:00Added an answer on May 31, 2026 at 9:18 pm

    In short

    they come from to different conceptualizations that, in some languages where double dispatch is not natively supported, lead to the visitor pattern as a way to concatenate two (or more) single dispatch in order to have a multi-dispatch surrogate.

    In long

    The idea of multiple dispatch is – essentially – allow a call like

    void fn(virtual base_a*, virtual base_b*); (note: not as a class member: this is NOT C++! )

    that can be overridden as

    void fn(virtual derived_a1*, virtual derived_b1*);
    void fn(virtual derived_a2*, virtual derived_b1*);
    void fn(virtual derived_a1*, virtual derived_b2*);
    void fn(virtual derived_a2*, virtual derived_b2*);
    

    so that, when calling

    fn(pa, pb)
    

    the call is redirected to the override that matches the actual runtime type of both pa and pb. (You can generalize this to whatever number of parameters)

    In language like C++, C#, Java, this mechanism does not exist and runtime type dispatching basically works with just one parameter (that, being just one, is made implicit in the function by making the function itself member of the class:

    in other words, the pseudocode

    void fn(virtual base_a*, base_b*) 
    

    becomes the (real C++)

    class base_a
    {
    public:
        virtual void fn(base_b*);
    }
    

    Note that here there is no more virtual in front of base_b, that from now is static.
    A call like

    pa->fn(pb) if pa points to a derived_a2 and pb to a derived_b1 will be dispatched to
    derived_a2::fn(base_b*), no matter if there is a derived_a2::fn(derived_b1*) in there: the run-time type of the object pointed by pb is not taken into account.

    The idea of the visitor patter is that you call the virtual dispatch of an object that calls (eventually back) the virtual dispatch of another:

    class base_a
    {
    public:
       virtual void fn(base_b*)=0;
       virtual void on_visit(derived_b1*)=0;
       virtual void on_visit(derived_b2*)=0;
    };
    
    class base_b
    {
    public:
       virtual void on_call(derived_a1*)=0;
       virtual void on_call(derived_a2*)=0;
    };
    
    //forward declarations, to allow pointers free use in other decls.
    class derived_a1;
    class derived_b1;
    
    
    class derived_a1: public base_a
    {
    public:
       virtual void fn(base_b* pb) { pb->on_call(this); }
       virtual void on_visit(derived_b1* p1) { /* useful stuff */ }
       ...
    };
    
    class derived_b1: public base_b
    {
    public:
      virtual void on_call(derived_a1* pa1) { pa1->on_visit(this); }
      ... 
    };
    

    now, a call like pa->fn(pb), if pa points to derived_a1 and pb to derived_b1, will finally go to derived_a1::on_visit(derived_b1*).

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

Sidebar

Related Questions

Is there any difference between double dispatch and visitor pattern? I'm working with Java
I've read about the difference between double precision and single precision. However, in most
In xquery, is there any difference between single and double quotes?
What is the difference between a single precision floating point operation and double precision
So I (think I) understand the difference between Float, Double, and Decimal , but
What is the difference between double.Parse(myString) and Double.Parse(myString) ? Is there a difference in
I know that in PHP, the only difference between double quotes and single quotes
Possible Duplicate: When to Use Double or Single Quotes in JavaScript Difference between single
In JavaScript, is there a performance difference between using a double equals ( ==
What is the difference between single quotes and double quotes in SQL?

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.