Visitor in two calls: double dispatch, explained
transcript
How does tax know it's looking at a gadget? It doesn't check. It's told.
The cart calls accept on the gadget, passing the tax visitor. The gadget's own accept runs. That's the first choice, made by the item. It calls visit gadget on the tax visitor, passing itself. That's the second choice, made by the visitor. Now tax holds a gadget, and adds 269. No type check anywhere.
Why not one visit method per kind and no accept? Because Java and C plus plus pick an overload from the declared type. A variable declared as an item matches none of them. Accept hands the real class back into the choice.
Python has no overloading by type, and neither does JavaScript. So without accept, you'd write a type check inside the visitor. Accept removes it.
The item picks first. The visitor picks second. That's double dispatch.
Full breakdown in the lecture.