多态的本质:同一函数接口在接受不同的类型参量时表现出不同的行为--多态是面向接口编程...

一、多态的本质

多态的本质:同一函数接口在接受不同的类型参量时表现出不同的行为:

不同对象能够调用同一接口,是因为它们含有统一的抽象纬度:接口;

同一函数能够接受不同对象的调用,是因为函数的参量是一个抽象类型(接口);

环境变量(主体类型)作为接口函数的特殊输入对接口的实现起着决定性的作用;

同一个接口函数声明针对不同的参量组合,定义了不同的函数实现;

函数作为参量时也具有类型(函数式编程)。

 

二、多态的语言学含义

多态是面向接口编程的概念

在面向对象或面向接口编程中,是一种接口的抽象能力

Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

 

Polymorphism is the ability of the programmer to write methods of the same name that do different things for different types of objects, depending on the needs of those objects.

 

所谓的多态是将类似的不同实现统一到一个(组)接口的能力;

涉及到两个方面:1)抽象能力;2)面向接口(忽略载体、对象)。

 

三、多态的支撑系统

动态绑定;

动态派发;

 

四、多态的分类解释

面向接口的多态:不同的类型对同一接口有不同的实现;所以有不同的行为;

面向泛型的多态:不同的具体类型可以共享同一个具体的函数实现;

 

五、多态概念的历史与分类

Christopher Strachey (1967) introduced the concept of polymorphism informally into procedural programming languages by distinguishing functions

  • that work differently on different argument types(相同的接口不同类型的参量,主要指缺省类型不同);
  • that work uniformly on a range of argument types (相同的接口不同的参量相同的行为,参量具有某些共同特征:泛型与函数式编程)类型约束。
  • 本质上为缺省类型多态与类型约束多态,其它的多态形式没有意义。
  • 函数也有类型,尤其是在函数式编程中(作为参量使用时)

He defined the former as ad-hoc polymorphism and the latter as parametric polymorphism:

"Ad-Hoc polymorphism is obtained when a function works, or appears to work, on several different types (which may not exhibit a common structure) and may behave in unrelated ways for each type.  Parametric polymorphism is obtained when a function works uniformly on a range of types; these types normally exhibit some common structure." (Strachey, 1967)

polymorphism

https://www.cnblogs.com/feng9exe/p/9151549.html

 

https://blog.csdn.net/wocalenimade/article/details/53448777

 

六、参考文献

https://www.cnblogs.com/feng9exe/p/8303789.html

https://www.cnblogs.com/feng9exe/p/8303815.html

https://www.cnblogs.com/feng9exe/p/9673779.html

转载于:https://www.cnblogs.com/feng9exe/p/10531793.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值