页数:15页文件大小:91.3 KB来源: 计算机专业英语ppt课件
本课件对应5.3 Object-Oriented Programming(面向对象程序设计)一节,讲解对象、类、封装与继承等核心概念,说明消息传递与数据隐藏带来的复用与维护优势。课文配中英文对照译文、生词短语表与课后练习,可用于课堂讲授与课前预习。
| 单词 | 词性 | 中文释义 |
|---|---|---|
| complicate | v. | (使)变复杂 |
| delegation | n. | 代表团,授权 |
| encapsulation | n. | 包装,封装 |
| implementation | n. | 执行 |
| individual | n. | 个体 |
| adj.个别的,单独的inheritance | n. | 遗传,遗产,继承 |
| introspection | n. | 内省,反省 |
| penalty | n. | 处罚 |
| polymorphism | n. | 多形性,多态现象 |
| prototype | n. | 原型 |
| via | prep. | 通过,经由 |
| 短语 | 中文释义 |
|---|---|
| do away with | 废除 |
| AbbreviationsCLOS(Common LISP Object System) | 公共 |
| LISP | 对象系统. |
| OOP(Object-Oriented Programming) | 面向对象的程序设计 |
| RTTI(Run Time Type Information) | 运行时类型信息 |
Object-oriented programming(OOP)refers to a special type of programming that combines datastructures with functions to create re-usable objects.面向对象的程序设计涉及一种专用类型的程序设计,该技术将数据结构与函数相结合产生可重用的对象。
另一方面,术语“面向对象”通常用来描述一种系统,这种系统主要处理不同类型的对象,在这儿人们所采取的行为取决于他们正处理的对象的类型。例如,一种面向对象的绘图程序能使人们绘制多种类型的对象,如圆、长方形和三角形等。但是,将同样的行为应用于不同的对象将产生不同的结果。例如,如果这一行为是制作三维,结果将分别形成球体、长方体和棱锥。
Otherwise, the term object-oriented is generally used to describe a system that deals primarily with different types of objects, and where you can take the actions depends on what type of object you are manipulating. Forexample, an object-oriented draw program might enable you to draw many types of objects, such as circles, rectangles, triangles, etc. Applying the same action to each of these objects, however, would produce different results. If the action is Make 3 D, for instance, the result would be a sphere, box, and pyramid, respectively.
Many languages support objectoriented programming. In OOPdataand functions are grouped together in objects (encapsulation). Anobjectisa particular instance of a class.[1]Eachobject can contain different data, but all objects belonging to a class have the same functions (called methods). Soyoucould have a program with manye-mail objects, containing different messages, but they would all have the same functionality, fixed by the email class. Objects often restrict access to the data (data hiding).分析:本句是并列句,but连接表转折意义的两个分句。后一个分句中,belonging to a class为现在分词短语作objects的后置定语。
许多语言都支持面向对象的程序设计。在面向对象的程序设计中,数据和功能组合在一起归入对象内(封装)。一个对象是一个类的特例。每一个对象可以包含不同的数据,但属于同一个类的所有对象具有相同的功能(称为方法)。于是,人们可以有一个带有许多电子邮件对象的程序,这些电子邮件对象包含有不同的信息,但具有电子邮件类固有的相同的功能。对象经常限制对数据的访问(数据隐藏)。
类很像类型——它们之间的关系会很复杂,而且随着语言的变化而变化。
Classesarea lot like types—the exact relationship between types and classes can be complicated and varies from language to language.
Via inheritance, hierarchies of objects can share and modify particular functions. Youmayhave code in one class that describes the feature salle-mails have (a sender and a date, forexample)andthen, in asub-class for email containing pictures, add functions that display images.[2]Often in the program you will refer toane-mail object as if it was the parent (super-class)because it will not matter whether thee-mail contains a picture, or sound, or just text. Thiscodewill not need to be altered when you add another sub-class of e-mail objects, containing (say)electronic cash.分析:本句是复合句。主句中的as if it was the parent为as if引导的虚拟语气的方式状语从句,如果表示与目前事实不符,谓语用一般过去式。在原因状语从句because it will not matter whether the email contains a picture, sound or just text.中,it为形式主语,而主语从句whether the email contains a picture, sound or just text为真正主语。
通过继承,不同级别的对象可以共享和修改特殊的功能。可以在一个类中有代码描述所有邮件具有的特点(例如:发送者和日期),而在包含图片的子类中,增加显示图像的功能。在程序中人们经常查阅电子邮件对象,把它看作父类;因为该邮件是否包含图片、声音或仅仅一种文本无关紧要。当你添加另一个邮件对象的子类(譬如包含电子现金)的时候,不需要改变代码。
有时候人们可能希望在父类上的一个行为可以根据子类的“真实”内容产生结果。例如:你可能想显示邮件对象的列表并且希望每个子类(文本,图像等)显示出不同的颜色。很多语言都可能具有多态性,即父类具有功能使子类为适应它们自己的目的而变化(多态性,由编译器使用动态绑定技术来实现)。这样,每个邮件子类可以提供默认打印功能的选择,用自己的颜色显示。
Sometimes you may want an action on a super-class to produce a result that depends on what sub-class it"really is". Forexample, you may want to display a list of email objects and want each sub-class (text, image, etc)to display in a different colour. In many languages it is possible for the super-class to have functions that sub-classes change to suit their own purposes (polymorphism, implemented by the compiler using a technique called dynamic binding). Soeachemail sub-class may supply an alternative to the default, printing function, with its own colour.
In many OOlanguages it is possible to find out what class an object is (runtime type information)and even what functions are connected with it (introspection/reflection). Others, like C++have little runtime information available (atleast in the standard language—individual libraries of objects can support RTTIwith their own conventions).[3]There are atleast three approaches to OOlanguages: Methods in Classes, Multi-Methods Separate from Classes, Prototypes.分析:本句是简单句。句中approach为名词,意为方法,后常跟to+名词意为“对待……”的方法。冒号后的Methods in Classes, Multi-Methods Separate from Classes, Prototypes为approaches的同位语。
在很多面向对象的语言中,可以找出一个对象属于哪个类(运行时信息),甚至与其相关的函数(内省)。其他的像C++则没有可用的运行时信息(至少在标准语言,对象的个别的库以它们自己的约定支持运行时信息)。至少有三种方法处理面向对象的语言:类的方法、与类分离的多方法、原型。
类的方法
Smalltalk以及其后的许多语言都将方法与类关联。方法形成类定义的一部分,并且语言实现每个类有一个虚函数表将方法与执行联系起来。为了允许多态性,这种间接是必需的,但引起了性能下降。在某些语言中(至少C++),只有程序员标记为虚拟的某些方法用这种方式来处理。
Methods in Classes
Many languages follow Smalltalkin associating functions (methods)with classes. The methods form part of a class definition and the language implementation will have (this is a low-level detail hidden from the programmer)avtable for each class which links methods to their implementations. This in direction is necessary to allow polymorphism, but introduces a performance penalty. In some languages (C++, atleast), only some methods, marked as virtual by the programmer, are treated in this way.
与类分离的多方法某些语言(例如CommonLisp/CLOS),允许函数专门研究不同变量的类以进行函数传递(多方法),多个函数不能和一个类相关联,因为类的不同结合可能存在不同的函数版本。Multi-Methods Separate from Classes Some languages(e.g.CommonLisp/CLOS)allow functions to specialise on the class of any variable that they are passed(multi-methods).Functions cannot be associated with one class because different versions of the function may exist for many different combinations of classes.
Prototypes Other OOlanguages do away with classes completely (e. g. Self). Prototype-based languages create new objects using an existing object as an example (prototype). Apart from solving some problems with dynamic object creation, this approach also encourages delegation (function calls are passed to other objects)rather than inheritance.
原型
其他面向对象的语言完全取消了类(例如Self)。基于原型的语言将已有的对象作为范例(原型)生成新的对象。除了解决一些动态对象产生的问题之外,这种方法还鼓励授权(函数调用被传递到其他对象)而不是继承。
习题5.3 一 判断正误:根据课文内容判断下列说法正误。
Put“true”or“false”in the brackets for the following statements according to the passage.
习题5.3 二 练习:根据课文内容完成下列练习。
Fillinthe blanks according to the passage.
习题5.3 三 翻译:将下列单词和短语译成中文。
Translate the following words and expressions into Chinese.
下载地址:{{downurl}}
{{{a}}}
{{#b}}{{{b}}}
{{/b}} {{/title}} {{#nolog}}登陆注册
{{/nolog}} {{#djsx}}点我刷新
{{/djsx}} {{#gocz}} {{/gocz}} {{#ffqr}} {{/ffqr}}