《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 05 Object-Oriented Programming

The c ++ Programming Language Lecture 5 Object-Oriented Programming
The C++ Programming Language Lecture 5: Object-Oriented Programming

Basic Concepts
Basic Concepts

Object Based object Oriented u Object Based Programming Classes regarded as new data types Single layer in hierarchy Not convenient in"Entity-Relation" relationship s has is implemented of Object Oriented Programming Focus on the relationship between classes Hierarchical in structure Good at Entity-Relation" relationship Main features: inheritance and polymorphism
Object Based & Object Oriented ◼ Object Based Programming ◼ Classes regarded as new data types ◼ Single layer in hierarchy ◼ Not convenient in “Entity-Relation” relationship – “is-a” – “has-a” – “is implemented of” ◼ Object Oriented Programming ◼ Focus on the relationship between classes ◼ Hierarchical in structure ◼ Good at “Entity-Relation” relationship ◼ Main features: inheritance and polymorphism

Inheritance u Organize those related classes and share their common data and operations a Parent/child relationship Parent(Base) class: defined common public interfaces and private implements of all child classes Child (derived) class: could override what is inherited, or add new implementations to fit its speciality
Inheritance ◼ Organize those related classes, and share their common data and operations ◼ Parent/child relationship ◼ Parent (Base) class: defined common public interfaces and private implements of all child classes ◼ Child (Derived) class: could override what is inherited, or add new implementations, to fit its speciality

Inheritance Hierarchy bstract Base Class> Lib Materials Books Magazine Files Rental Books Audio Books E-Books a If the root do not represent a real object, and it is only for design need we could call it Abstract Base Class( conceptual)
Inheritance Hierarchy ◼ If the root do not represent a real object, and it is only for design need, we could call it Abstract Base Class (Conceptual) Lib Materials Books Magazines Files Rental Books Audio Books E-Books Abstract Base Class →

Polymorphism J EXample void loan check in(LibMat& mat) mat.check inO if (mat is late) mat assess fine( if (mat. waiting listo matnotify available Since libat is an abstract base class and there are only real objects of class Renta/Book or Magazine in the program how could mat be instantiated and referenced?
Polymorphism ◼ Example void loan_check_in(LibMat& mat) { mat.check_in(); if (mat.is_late()) mat.assess_fine(); if (mat.waiting_list()) mat.notify_available(); } ◼ Since LibMat is an abstract base class, and there are only real objects of class RentalBook or Magazine in the program, how could mat be instantiated and referenced?

Polymorphism(cont.) u Polymorphism Use the pointer or reference of the base class to point to any object of its derived class Thus we got transparency that we manipulate those real objects in a type-independent way Same code will represent different objects and make different behaviors Code will remain same if the inheritance hierarchy changes
Polymorphism (cont.) ◼ Polymorphism ◼ Use the pointer or reference of the base class to point to any object of its derived class ◼ Thus we got transparency that we manipulate those real objects in a type-independent way ◼ Same code will represent different objects and make different behaviors ◼ Code will remain same if the inheritance hierarchy changes

Polymorphism(cont.) a Static Binding-common situation Which function entrance to use could be decided before execution a Dynamic Binding- mechanism of polymorphism Which version of the check _in should be called could only be decided during execution by the addressed real object that mat represents a Delay the resolution until run-time
Polymorphism (cont.) ◼ Static Binding – common situation ◼ Which function entrance to use could be decided before execution ◼ Dynamic Binding – mechanism of polymorphism ◼ Which version of the check_in() should be called, could only be decided during execution by the addressed real object that mat represents ◼ Delay the resolution until run-time

Class Hierarchy
Class Hierarchy

Implement a inheritance hierarchy u An example of 3 layers, LibMat derives Book, Book derives AudioBook We define a simple public interface, which containing only constructor, destructor and print function(each class has its own print way class libMan public: LibMatoI cout <<"LibMat Default Constructor!<< end; y virtual -LibMatoi cout << "LibMat Destructor! < endl; y virtual void print0 const{cout≤<“ This is a LibMat object!”<<endl; }
Implement a inheritance hierarchy ◼ An example of 3 layers: LibMat derives Book, Book derives AudioBook ◼ We define a simple public interface, which containing only constructor, destructor and print function (each class has its own print way) class LibMat { public: LibMat() { cout << “LibMat Default Constructor!” << endl; } virtual ~LibMat() { cout << “LibMat Destructor!” << endl; } virtual void print() const { cout << “This is a LibMat object!” << endl; } };
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 山东大学:《微机原理及单片机接口技术》课程教学资源(PPT课件讲稿)第二章 微型计算机基础知识.ppt
- 四川大学:《计算机操作系统 Operating System Principles》课程教学资源(PPT课件讲稿)第6章 存储器管理.ppt
- 《计算机系统和系统结构》课程教学资源(PPT课件讲稿)第四章 流水线技术.ppt
- 《计算机算法基础》课程教学资源(PPT课件讲稿)分枝-限界法.ppt
- 东南大学:《数据结构》课程教学资源(PPT课件讲稿)贪心算法.pptx
- 《网络编程实用教程》教学资源(PPT课件讲稿)第4章 MFC编程.ppt
- 航空航天(PPT课件讲稿)Mechanics——Particle Motion.ppt
- 上海交通大学:《软件工程导论》课程教学资源(PPT课件讲稿)第十三讲 软件项目中的人员管理.ppt
- Data Mining and Model Choice in Supervised Learning.ppt
- 武昌理工学院:《操作系统原理》课程教学资源(PPT课件)第一章 操作系统概述(主讲:温静).pptx
- 《Computer Networking:A Top Down Approach》英文教材教学资源(PPT课件讲稿,6th edition)Chapter 8 网络安全 Network Security.ppt
- 西安电子科技大学:《现代密码学》课程教学资源(PPT课件讲稿)第六章 数字签名算法.pptx
- 华中师范大学:智能与分布计算(PPT课件讲稿)语义网与本体 Semantic Web & Ontology(Introduction).ppt
- 中国科学技术大学:《计算机科学导论》课程教学资源(PPT课件讲稿)第五讲 经典计算的计算模型(主讲:陈意云).pptx
- 《高级语言程序设计 Advanced Programming》课程教学资源(PPT课件讲稿)第5章 循环结构程序设计.ppt
- 香港科技大学:Introduction to Software Defined Network(SDN).pptx
- 《微机原理笔记》课程教学资源(PPT课件讲稿)第6章 输入输出和中断技术.ppt
- 厦门大学:《大数据技术原理与应用》课程教学资源(PPT课件讲稿)第九章 图计算.ppt
- 《大型机高级系统管理技术》课程教学资源(PPT课件讲稿)第3章 作业控制语言.ppt
- 贵州师范学院:《高级语言程序设计 Advanced Programming》课程教学资源(PPT课件讲稿)第9章 结构体.ppt
- 四川大学:《计算机操作系统 Operating System Principles》课程教学资源(PPT课件讲稿)第7章 虚拟存储器管理.ppt
- 《计算机软件技术基础》课程电子教案(PPT课件讲稿)第9章 存储管理.ppt
- 上海交通大学:传感器网络研究 Research On Sensor Nets(主讲:伍民友).ppt
- 南京航空航天大学:《数据结构》课程教学资源(PPT课件讲稿)第五章 数组和广义表.ppt
- 《大数据挖掘与应用技术》课程教学资源(PPT课件讲稿)第12章 Hibernate持久化技术.ppt
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第7章 多处理器及线程级并行 7.3 分布式共享存储器体系结构 7.4 Models of Memory Consistency.pptx
- Acknowledged Broadcasting and Gossiping in ad hoc radio networks.ppt
- Apache Spark:Intro to Spark(Lightning-fast cluster computing).pptx
- 中国科学技术大学:《网络信息安全 NETWORK SECURITY》课程教学资源(PPT课件讲稿)第三章 局域网安全技术及应用.ppt
- 面向服务的业务流程管理(PPT讲稿)Business Process Analysis and Modeling.pptx
- 中国铁道出版社:《局域网技术与组网工程》课程教学资源(PPT课件讲稿)第6章 Internet.ppt
- 《计算机视觉》课程教学资源(PPT课件讲稿)第二章 视觉的基本知识 第二节 视觉物理学特性.pptx
- 北京航空航天大学:《程序设计语言原理》课程教学资源(PPT课件)第0章 绪论(主讲:吕卫锋)程序语言设计方法学 The Methodology Of Programming Language.ppt
- 《单片机原理及应用》课程PPT教学课件(C语言版)第1章 单片机基础知识概述.ppt
- 山西管理职业学院:《Excel 教程》课程教学资源(PPT课件讲稿,共九部分).ppt
- 《文献信息检索与利用》课程教学资源(PPT课件)第三章 文献信息检索基本理论.ppt
- 南京大学:《操作系统》课程教学资源(PPT课件讲稿)文件管理(主讲:徐锋).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)敏捷软件开发 Agile Software Development.ppt
- 计算机的维修(PPT课件讲稿)计算机维修的基本知识与实例.ppt
- 四川大学:《计算机系统结构》课程教学资源(PPT课件讲稿)第1章 计算机系统结构基本概念(主讲:倪云竹).ppt