What is the real significance(use) of polymorphism

前端 未结 10 2376
别跟我提以往
别跟我提以往 2020-12-01 01:44

I am new to OOP. Though I understand what polymorphism is, but I can\'t get the real use of it. I can have functions with different name. Why should I try to implement polym

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 02:15

    One of the most significant benefit that you get from polymorphic operations is ability to expand. You can use same operations and not changing existing interfaces and implementations only because you faced necessity for some new stuff.

    All that we want from polymorphism - is simplify our design decision and make our design more extensible and elegant. You should also draw attention to Open-Closed Principle (http://en.wikipedia.org/wiki/Open/closed_principle) and for SOLID (http://en.wikipedia.org/wiki/Solid_%28Object_Oriented_Design%29) that can help you to understand key OO principles.

    P.S. I think you are talking about "Dynamic polymorphism" (http://en.wikipedia.org/wiki/Dynamic_polymorphism), because there are such thing like "Static polymorphism" (http://en.wikipedia.org/wiki/Template_metaprogramming#Static_polymorphism).

提交回复
热议问题