Chapter 13 Object-Oriented Programming Polymorphism 0 2018, SEU. All rights reserved. 1
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 1 Object-Oriented Programming: Polymorphism Chapter 13
OBJECTIVES What polymorphism(多态)i, how it makes programming more convenient, and how it makes systems more extensible and maintainable ° To declare and use virtual functions(虚函数)to effect polymorphism The distinction between abstract and concrete classes(抽象类和具体类 ° To declare pure virtual functions(纯虚函数)to create abstract classes 0 2018, SEU. All rights reserved. 2
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 2 OBJECTIVES What polymorphism(多态) is, how it makes programming more convenient, and how it makes systems more extensible and maintainable. To declare and use virtual functions(虚函数) to effect polymorphism. The distinction between abstract and concrete classes(抽象类和具体类). To declare pure virtual functions(纯虚函数) to create abstract classes
Topics 13.1 Introduction o 13. 2 Relationships Among Objects in an Inheritance hierarchy 13.3 Type Fields and switch Statements 13. 4 Abstract Classes and pure virtual functions o 13.5 Case Study: Payroll System Using Polymorphism 0 2018, SEU. All rights reserved. 3
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 3 Topics 13.1 Introduction 13.2 Relationships Among Objects in an Inheritance Hierarchy 13.3 Type Fields and switch Statements 13.4 Abstract Classes and Pure virtual Functions 13.5 Case Study: Payroll System Using Polymorphism
13.1 Introduction -通用化编程需求 画板 Tool 基类 Shape:长方形*2、椭圆形*3、三角形*4、菱形*5等 用 vector或者arry来保存指针 °基类指针vs派生类指针 当需更新画板时,枚举指针并调用各自draw函数 当需计算面积时,枚举指针并调用各自area函数 0 2018, SEU. All rights reserved. 4
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 4 13.1 Introduction ---通用化编程需求 基类Shape:长方形*2、椭圆形*3、三角形*4、菱形*5等 用vector或者array来保存指针 基类指针 vs 派生类指针 当需更新画板时,枚举指针并调用各自draw函数 当需计算面积时,枚举指针并调用各自area函数 画板 Tool
13.1 Introduction 需 求 °用户通过键盘输入多个员工信息,统计收入数据 (1)CommissionEmployee name, ssn, grosssales, commisionRate (2)BasePlus Commission Employee name, ssn, grossSales, commisionRate, base Salary °用 vector或者aray来保存指向员工对象的指针 o Commission Employee pointer 希望通过这些通用指针来调用各自的 earnings0函 数以进行统计 o 2018, SEU. All rights reserved 5
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 5 用户通过键盘输入多个员工信息,统计收入数据: (1)CommissionEmployee name, ssn, grossSales, commisionRate (2)BasePlusCommissionEmployee name, ssn, grossSales, commisionRate, baseSalary 用vector或者array来保存指向员工对象的指针 CommissionEmployee Pointer 希望通过这些通用指针来调用各自的earnings()函 数以进行统计 13.1 Introduction --- 需 求