版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C+ Object-oriented Programming,Zhao,Qingjie Beijing Institute of Technology,1. Introduction to Objects,Zhao,Qingjie Beijing Institute of Technology,1.1 The progress of abstraction,All programming languages provide abstractions.(class in C+) The complexity of the problems youre able to solve is direc
2、tly related to the kind and quality of abstraction. Procedural languages (Fortran, BASIC, and C) require you to think in terms of the structure of the computer. Object-oriented languages require you to think in terms of the structure of the problem you are trying to solve.,Procedural paradigm: Progr
3、am= (Algorithms + Data structures) Object-oriented paradigm: Object =( Algorithms + Data structures ) Program=(Object1 + Object2 +),Characteristics of OOP,Everything is an object. A program is a bunch of objects telling each other what to do by sending messages. Each object has its own memory made u
4、p of other objects. Every object has a type. All objects of a particular type can receive the same messages.,Encapsulation (abstract data type) Inheritance polymorphism,OOP:,Creating abstract data types (classes) is a fundamental concept in object-oriented programming. You can create variables (obje
5、cts or instances) of a class (type) and manipulate those variables (sending messages or requests). A class describes a set of objects that have identical characteristics (data elements) and behaviors (functionality).,class Date public: int year() return y; int month() const return m; int day() retur
6、n d; private: int y, m, d ; ; Date a, b;,1.2 An object has an interface,The interface establishes what requests you can make for a particular object. A class has a function associated with each possible request, and when you make a particular request to an object, that function is called.,1.3 The hi
7、dden implementation,class creator: build a class that exposes only whats necessary to the client programmer and keeps everything else hidden. client programmer: collect a toolbox full of classes to use for rapid application development. Hiding the implementation reduces program bugs.,Access specifie
8、rs,public, private, protected “public” means the following definitions are available to everyone. “private” means that no one can access those definitions except the creator of the class, inside member functions of that class. “private” is a brick wall between the class creator and the client progra
9、mmer. “protected” acts just like private, with the exception that an inheriting class has access to protected members, but not private members.,Access control,Access control can keep client programmers hands off portions they shouldnt touch. Access control allows the library designer to change the i
10、nternal workings of the class without worrying about how it will affect the client programmer.,1.4 Reusing the implementation,Composition: use an object of a class directly. Inheritance: clone the existing class and then make additions and modifications to the clone.,1.5 Inheritance: reusing the int
11、erface,base class, parent class derived class, inherited class, sub class, child class,When you inherit from an existing type, you create a new type. This new type contains not only all the members of the existing type, but more importantly it duplicates the interface of the base class. The derived
12、class can be the same type as the base class. In the previous example, “a circle is a shape.” To differentiate your new derived class from the original base class, you can add new functions to the derived class, or overriding an existing base-class function.,1.6 Interchangeable objects with polymorp
13、hism,Connecting a function call to a function body is called binding. When binding is performed before the program is run (by the compiler and linker), its called early binding. The binding occurring at runtime is called late binding, or dynamic binding or runtime binding. Polymorphism is realized b
14、y using the keyword virtual to declare a function having the flexibility of late-binding properties.,1.7 Creating and destroying objects,Where is the data for an object ? How is the lifetime of that object controlled? The static storage area is simply a fixed patch of memory that is allocated before
15、 the program begins to run. The stack is an area in memory that is used directly by the microprocessor to store data during program execution. The heap is managed dynamically at runtime. “new” is used to create a new object (storage), and “delete” is used to release the storage.,1.8 Exception handli
16、ng: dealing with errors,Exception handling wires error handling directly into the programming language and sometimes even the operating system. An exception is an object that is “thrown” from the site of the error and can be “caught” by an appropriate exception handler designed to handle that partic
17、ular type of error. Exception handling does not interfere with the normally-executing code.,1.9 Analysis and design,Make a plan The mission statement What are we making? requirements analysis and system specification How will we build it? Build the core Iterate the use cases Evolution,1.10 Extreme p
18、rogramming,Write tests first Pair programming,1.11 Why C+ succeeds,To solve many other problems facing developers today, especially those who have large investments in C. The goal of C+ is improved productivity.,A better C Youre already on the learning curve Efficiency Systems are easier to express and understa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 北京病人护理伦理与实践
- 护理环境与患者满意度调查
- 护理安全事件责任认定
- 金太阳陕西省2026届高三下学期3月联考化学(26-287C)+答案
- 护理技术操作培训:静脉注射药物配置
- 护理认知评估方法
- 护理课件演讲的演讲稿自信心提升策略
- 基于云计算的远程教育技术实践
- 临床研究协调员职业发展规划
- 基于用户行为的营销策略调整
- 口腔正畸考核制度
- ARM Cortex-A9多核嵌入式系统开发教程
- 2026年《必背60题》通信工程专业26届考研复试高频面试题包含详细解答
- 2026年生活会上“红脸出汗”的相互批评意见(六大类60条)
- 2026年鄂尔多斯职业学院单招职业倾向性测试题库附答案解析
- 2025-2026学年苏科版八年级下册数学 第十章 分式 单元巩固测试卷(含答案)
- 古诗词诵读《涉江采芙蓉》教学课件统编版高中语文必修上册
- 财务的兼职合同范本
- 2025年智慧医院建设项目可行性研究报告
- 解除土地租赁合同协议书
- 机场防鸟撞培训大纲
评论
0/150
提交评论