泛型理论及抽象方向

泛型编程不仅能泛化算法中涉及的概念(数据类型),还能泛化行为(函数、方法、运算)。

 

基础部分:

与类型无关的变量和函数,通用部分;

 

扩展部分(swift):

与类型相关的函数其它扩展;

 

泛型关注通用的算法和数据组织形式;

关注与类型无关的算法和数据组织形式;

 

偏重数据的泛型(强泛型成员变量)关注数据的组织及在此组织上的算法;

偏重算法的泛型强调算法的通用性;

 

类型无关性:类型无关的数据组合形式和算法

Using parametric polymorphism, a function or a data type can be written generically so that it can handle values identically without depending on their type.[1] Such functions and data types are called generic functions and generic datatypes respectively and form the basis of generic programming.

 

https://en.wikipedia.org/wiki/Parametric_polymorphism

 

 抽象的方向:

泛型:跨类型抽象,多个类型的通用部分;

构造型抽象;

 

接口类:多个类型具有共同的数据和建立在确定类型上的接口行为;

继承性抽象;

 

typeclass:

同时具有上述两种特征。

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

 

posted @ 2019-03-11 16:56  zzfx  阅读(330)  评论(0编辑  收藏  举报