12.1多态性的概念 多态性(polymorphism)是面向对象程序设计的 一个重要特征。 当向不同的对象发送同一个消息时,不同的对 象在接收时会产生不同的行为。 通过继承产生的不同层次的派生类,与基类成 员同名的成员在不同的派生类中有不同的含 义。也可以说,多态性是“一个接口,多种 方法” 2017年4月26日星期 第12章多态性与虚函数 0雪2时14分39秒 BACK NEXT
HOME2017年4月26日星期 三12时14分39秒 第12章 多态性与虚函数 6 多态性(polymorphism)是面向对象程序设计的 一个重要特征。 当向不同的对象发送同一个消息时,不同的对 象在接收时会产生不同的行为。 通过继承产生的不同层次的派生类,与基类成 员同名的成员在不同的派生类中有不同的含 义。也可以说,多态性是“一个接口,多种 方法”
动态多态性,又称运行时多态性,在程序运行 过程中才动态地确定操作所针对的对象,通 过虚函数(virtual function)实现。 通过继承而产生了相关的不同的派生类,与基 类成员同名的成员在不同的派生类中有不同 的含义。也可以说,多态性是“一个接口, 多种方法”。 2017年4月26日星期 第12章多态性与虚函数 H0雪2时14分39秒 BACK NEXT
HOME2017年4月26日星期 三12时14分39秒 第12章 多态性与虚函数 7 动态多态性,又称运行时多态性,在程序运行 过程中才动态地确定操作所针对的对象,通 过虚函数(virtual function)实现。 通过继承而产生了相关的不同的派生类,与基 类成员同名的成员在不同的派生类中有不同 的含义。也可以说,多态性是“一个接口, 多种方法”
从系统实现的角度看,多态性分为两类: 静态多态性,又称编译时多态性,在程序编译 时系统就能决定调用的是哪个函数,如函数 重载和运算符重载。 动态多态性,又称运行时多态性,在程序运行 过程中才动态地确定操作所针对的对象,通 过虚函数(virtual function)实现。 017年4月26日星期 第12章多态性与虚函数 8 HOME 12时14分39秒 BACK NEXT
HOME2017年4月26日星期 三12时14分39秒 第12章 多态性与虚函数 8 从系统实现的角度看,多态性分为两类: 静态多态性,又称编译时多态性,在程序编译 时系统就能决定调用的是哪个函数,如函数 重载和运算符重载。 动态多态性,又称运行时多态性,在程序运行 过程中才动态地确定操作所针对的对象,通 过虚函数(virtual function)实现
The concept of polymorphism Polymorphism (implemented in C++with virtual functions)is the third essential feature of an object oriented programming language, after data abstraction and inheritance. Polymorphism allows improved code organization and readability as well as the creation of extensible programs that can be “grown”not only during the original creation of the project,but also when new features are desired. 2017年4月26日星期 第12章多态性与虚函数 0画2时14分39秒 BACK
HOME2017年4月26日星期 三12时14分39秒 第12章 多态性与虚函数 9 Polymorphism (implemented in C++ with virtual functions) is the third essential feature of an object oriented programming language, after data abstraction and inheritance. Polymorphism allows improved code organization and readability as well as the creation of extensible programs that can be “grown” not only during the original creation of the project, but also when new features are desired
The virtual function allows one type to express its distinction from another,similar type,as long as they're both derived from the same base type.This distinction is expressed through differences in behavior of the functions that you can call through the base class. 017年4月26日星期 第12章多态性与虚函数 HOME 10 12时14分39秒 BACK NEXT
HOME2017年4月26日星期 三12时14分39秒 第12章 多态性与虚函数 10 The virtual function allows one type to express its distinction from another, similar type, as long as they’re both derived from the same base type. This distinction is expressed through differences in behavior of the functions that you can call through the base class