計算機程式 第十三單元 Inheritance 授課教師:廖婉君教授 【本著作除另有註明外,採取創用 CC 「姓名標示 -非商業性-相同方式分享」台灣 3.0 版授權釋出】創用 CC 「姓名標示 -非商業性-相同方式分享」台灣 3.0 版 本課程指定教材為 C++ How to Program, 7/e, Harvey M. Deitel and Paul J. Deitel, both from Deitel & Associates, Inc. © 2010 。 本 講義僅引用部分內容,請讀者自行準備。 1 本作品轉載自 Microsoft Office 2007 多媒體藝廊,依據 Microsoft 服務合約及著作權法 第 46 、 52 、 65 條合理使用。 Microsoft 服務合約
An Overview Create new class from existing class o Base class vs. derived class o Absorb base class’s data and behavior o Enhance with new capabilities More specialized group of objects Behaviors inherited from base class Additional and customized behavior Three types of inheritance o Public, protected, and private 2 Derived Class: Car Base Class: Vehicle
An Overview (cont.) Base classes and derived classes o Object of one class “is an” object of another class o Base class typically represents a larger set of objects than derived class Example: o Base class: vehicle Includes cars, trucks, boats, bicycles, etc. o Derived class: car Smaller, more-specific subset of vehicle 3
Class Hierarchy Direct base class o Inherited explicitly (one level up hierarchy) Indirect base class o Inherited two or more levels up hierarchy Single inheritance o Inherits from one base class Multiple inheritance o Inherits from multiple base classes Base classes possibly unrelated 4
Class Hierarchy (cont.) 5 CommunityMembe r EmployeeStudentAlumnus FacultyStaff AdministratorTeacher AdministratorTeacher Single inheritanc e Multiple inheritanc e
Outline Commission Employee.h 6 p
Outline Commission Employee.cpp 7 p
Outline fig12_06.cpp 8 p.531
Outline BasePlus Commission Employee.h 9 p
Outline BasePlus Commission Employee.cpp 10 p
Outline fig12_09.cpp 11 p.536
Outline BasePlus Commission Employee.h 12 p.538
Outline BasePlus Commission Employee.cpp 13 p
Outline Commission Employee.h 14 p
Outline Commission Employee.cpp 15 p
Outline BasePlus Commission Employee.h 16 p
Outline BasePlus Commission Employee.cpp 17 p
Outline Fig12_16.cpp 18 p
Outline Commission Employee.h 19 p.550
Outline Commission Employee.cpp 20 p
Outline BasePlus Commission Employee.h 21 p.553
Outline BasePlus Commission Employee.cpp 22 p
Outline Commission Employee.h 23 p
Outline Commission Employee.cpp 24 p
Outline BasePlus Commission Employee.h 25 p
Outline BasePlus Commission Employee.cpp 26 p
Outline fig12_26.cpp 27 p
版權聲明 28 頁碼作品版權圖示來源 / 作者 1-29 本作品轉載自 Microsoft Office 2007 多媒體藝廊,依據 Microsoft 服務合約及著作權法第 46 、 52 、 65 條合理使用。 2 Open Clip Art Library ,作者: TheresaKnott ,本作品轉載自: ,瀏覽日期: 2013/1/16 。 2 Open Clip Art Library ,作者: netalloy ,本作品轉載自: ,瀏覽日期: 2013/1/16 。 2 Open Clip Art Library ,作者: Anonymous ,本作品轉載自: ,瀏覽日期: 2013/1/16 。 2 Open Clip Art Library ,作者: Machovka ,本作品轉載自: ,瀏覽日期: 2013/1/16 。
版權聲明 29 頁碼作品版權圖示來源 / 作者 4 Open Clip Art Library ,作者: Gerald_G ,本作品轉載自: , 瀏覽日期: 2013/1/16 。 4 Open Clip Art Library ,作者: Gerald_G ,本作品轉載自: , 瀏覽日期: 2013/1/16 。 4 Open Clip Art Library ,作者: Gerald_G ,本作品轉載自: , 瀏覽日期: 2013/1/16 。 5 C++ How to Program, 7/e ,作者: Harvey M. Deitel and Paul J. Deitel , 出版社: Deitel & Associates ,出版日期: 2010 , P.524 。 依據著作權法第 46 、 52 、 65 條合理使用。 6-27 Open Clip Art Library ,作者: aritztg ,本作品轉載自: ,瀏覽日期: 2013/1/10 。