Chapter 12 Object-Oriented Programming Inheritance 0 2018 SEU. All rights reserved. 1
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 1 Object-Oriented Programming: Inheritance Chapter 12
OBJECTIVES o To create classes by inheriting from existing classes o How inheritance promotes software reuse The notions of base classes and derived classes and the relationships between them o The protected member access specifier. o The use of constructors and destructors in inheritance hierarchies o The differences between public, protected and pri ivate inheritance The use of inheritance to customize existing g software 0 2018, SEU. All rights reserved. 2
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 2 OBJECTIVES To create classes by inheriting from existing classes. How inheritance promotes software reuse. The notions of base classes and derived classes and the relationships between them. The protected member access specifier. The use of constructors and destructors in inheritance hierarchies. The differences between public, protected and private inheritance. The use of inheritance to customize existing software
Topics 12.1 Introduction 122 Base classes(基类) and derived classes 派生类) 12.3 protected Members o 12.4 Relationship between Base classes and Derived classes o 12.5 Constructors and destructors in Derived Classes 12.6 public, protected and private Inheritance o 12.7 Software Engineering with Inheritance 0 2018, SEU. All rights reserved. 3
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 3 Topics 12.1 Introduction 12.2 Base Classes(基类) and Derived Classes (派生类) 12.3 protected Members 12.4 Relationship between Base Classes and Derived Classes 12.5 Constructors and Destructors in Derived Classes 12.6 public, protected and private Inheritance 12.7 Software Engineering with Inheritance
121 Introduction-继承的概念 °软件重用 °在已存在的类基础上构建新的类 吸纳已有类的数据及行为(数据成员及成员函数) °可以强化扩展一些新的功能 Graduate Student 重写? Student String Name String Name int Age int Age Void Exam 重用? Void Exam Void Research U 2UI0, SEU. All iGrs reserved
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 4 12.1 Introduction --继承的概念 软件重用 在已存在的类基础上构建新的类 吸纳已有类的数据及行为(数据成员及成员函数) 可以强化扩展一些新的功能 Student String Name int Age ……. Void Exam() Graduate Student String Name int Age ……. Void Exam() Void Research() 重写? 重用?
12.1 Introduction-类之间的关系 Shape(基类 public ls-a(继承 Inheritance protected Has-a(组合) (继承关系) private crce(派生类 声明格式: class<派生类名>:<继承方式><基类名> …} class Circle: public Shape....]; 图形 闭合图形 开放图形 多边形 椭圆形(折线)(直线(弧线 O 2018, SEt. All rights reserved. 5
© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 5 12.1 Introduction --类之间的关系 派生类 Inheritance (继承关系) public protected private 基 类 图 形 闭合图形 开放图形 多边形 椭圆形 折线 直线 弧线 Is-a(继承) Has-a(组合) Shape Circle 声明格式:class <派生类名>:<继承方式><基类名> {……}; class Circle: public Shape{……};