In OOP, is operator overloading in fact polymorphism or parameter overloading? -


Is operator overloading really polymorphic or overloading parameters?

Is it true that polymorphism is usually responding to different classes, the same "message" (method name) and do different things, so

  Bird.give_sound ()   

and

  car.give_sound ()   

can do different things and parameters Overloading is more about talking about the same class, while the different parameters (method names) sent with the message are separate while talking differently.

  bird.give_sound () < / Code>  

and

  bird.give_sound (: frighten_sound)   

may be different.

Is the operator overloading strictly overloading the parameters? At least in Ruby, sending +

  "foo" + "bar" "foo" + 3   

Foo containing the string message, sending the first line with a parameter string, the second one is sending the parameter 3, and + is slightly different. In the following example, The polymorph is:

  "foo" + 3 1 + 3   

Because + message invites various sections of different sections , But using the same message name, + Land. So in these 2 cases, they are polymorphism, not operator overloading?

Is the above accurate and correct? Is there something that can be added to it or is it right to be followed?

After

Thank you for explanation of the reference in your comment

as possible To summarize ...

Looking at the same method name (or "message"):

  • Different behaviors are overloaded based on parameter type,
  • There is a different behavior polymorphism based on the type of object.

Comments