What's the difference between Polymorphism and Multiple Dispatch?

后端 未结 7 1365
难免孤独
难免孤独 2021-01-30 10:52

...or are they the same thing? I notice that each has its own Wikipedia entry: Polymorphism, Multiple Dispatch, but I\'m having trouble seeing how the concepts differ.

<

7条回答
  •  星月不相逢
    2021-01-30 11:26

    if you want the conceptual equivalent of a method invocation

    (obj_1, obj_2, ..., obj_n)->method
    

    to depend on each specific type in the tuple, then you want multiple dispatch. Polymorphism corresponds to the case n=1 and is a necessary feature of OOP.

提交回复
热议问题