配色: 字号:
《计算机专业英语》Unit 8 Object-Oriented Programming
2023-05-24 | 阅:  转:  |  分享 
  
Unit 8 Object-Oriented ProgrammingContentsAfter you have read this un
it, you should be familiar with:1. What is OOP?2. Features of OOP
Learning ObjectivesWords&ExpressionsWords&ExpressionsWords&Expre
ssionsText Object-oriented programming (OOP) is a pro
gramming paradigm that uses "objects" to design applications and
computer programs. Programming techniques may include features su
ch as data abstraction, encapsulation, modularity, polymorphism,
and inheritance. It was not commonly used in mainstream software
application development until the early 1990s.Many modern program
ming languages now support OOP. For example: Java, C++, .NET, and
so on.Class Defines the abstract characteristics
of a thing (object), including the thing''s characteristics (its a
ttributes, fields or properties) and the thing''s behaviors (the t
hings it can do, or methods, operations or features). Text
One might say that a class is a blueprint or factory that describ
es the nature of something. For example, the class Dog would cons
ist of traits shared by all dogs, such as breed and fur color (ch
aracteristics), and the ability to bark and sit (behaviors). Clas
ses provide modularity and structure in an object-oriented comput
er program. The code for a class should be relatively self-contai
ned (generally using encapsulation). Collectively, the properties
and methods defined by a class are called members. Object
A pattern (exemplar) of a class. The class Dog def
ines all possible dogs by listing the characteristics and behavio
rs they can have; the object Lassie is one particular dog, with p
articular versions of the characteristics. Text A Dog ha
s fur; Lassie has brown-and-white fur. Instance One c
an have an instance of a class; the instance is the actual object
created at runtime. In programmer jargon, the Lassie object is a
n instance of the Dog class. The set of values of the attributes
of a particular object is called its state. The object consists o
f state and the behavior that''s defined in the object''s class. Me
thod An object''s abilities. In language, methods (
sometimes referred to as "functions") are verbs. Lassie, being a
Dog, has the ability to bark. So bark () is one of Lassie''s metho
ds. She may have other methods as well, Text for example s
it () or eat () or walk (). Within the program, using a method us
ually affects only one particular object; all Dogs can bark, but
you need only one particular dog to do the barking. Message passi
ng "The process by which an object sends data to an
other object or asks the other object to invoke a method". Also k
nown to some programming languages as interfacing. For example, t
he object called Breeder may tell the Lassie object to sit by pas
sing a "sit" message which invokes Lassie''s "sit" method. The syn
tax varies between languages, for example: [Lassie sit] in Object
ive-C. In Java, code-level message passing corresponds to "method
calling". Text Some dynamic languages use double-dispatch
or multi-dispatch to find and pass messages. Inheritance
"Subclasses" are more specialized versions of a class, which i
nherit attributes and behaviors from their parent classes, and ca
n introduce their own. For example, the class Dog mi
ght have sub-classes called Collie and Chihuahua. In this case, L
assie would be an instance of the Collie subclass. Suppose the Do
g class defines a method called bark() and a property called fur
Color. Text Each of its sub-classes (Collie, Chihuahua) will inhe
rit these members, meaning that the programmer only needs to writ
e the code for them once. Each subclass can alter its inherited
traits. For example, the Collie subclass might specify that the d
efault fur Color for a collie is brown-and-white. The Chihuahua s
ubclass might specify that the bark() method produces a high pitc
h by default. Subclasses can also add new members. The Chihuahua
subclass could add a method called tremble (). So an individual C
hihuahua instance would use a high-pitched bark() from the Chihua
hua subclass. Text The Chihuahua object would also have the
tremble () method, but Lassie would not, because she is a Collie,
not a Chihuahua. In fact, inheritance is an "a... is a" relation
ship between classes, while instantiation is an "is a" relationsh
ip between an object and a class: a Collie is a Dog ("a... is a")
, but Lassie is a Collie ("is a"). Thus, the object named Lassie
has the methods from both classes Collie and Dog. Multipl
e inheritance is inheritance from more than one ancestor class, n
either of these ancestors being an ancestor of the other. For exa
mple, independent classes could define Dogs and Cats, and a Chime
ra object could be created from these two which inherits all the
(multiple) behavior of cats and dogs. Text This is not alway
s supported, as it can be hard to implement. Abstraction
Abstraction is simplifying complex reality by modeling class
es appropriate to the problem, and working at the most appropriat
e level of inheritance for a given aspect of the problem.
For example, Lassie the Dog may be treated as a Dog much of
the time, a Collie when necessary to access Collie-specific attri
butes or behaviors, and as an Animal (perhaps the parent class of
Dog) when counting Timmy''s pets.Text Encapsulation
Encapsulation conceals the functional details of a class from obj
ects that send messages to it. For example, the Dog
class has a bark () method. The code for the bark () method defi
nes exactly how a bark happens (e.g., by inhale () and then exhal
e (), at a particular pitch and volume). Timmy, Lassie''s friend,
however, does not need to know exactly how she barks. Encapsulati
on is achieved by specifying which classes may use the members of
an object. The result is that each object exposes to any class a
certain interface. Members are often specified as public, protec
ted or private, determining whether they are available to all cla
sses, sub-classes or only the defining class. Some languag
es go further: Java uses the default access modifier to restrict
access also to classes in the same package, C# and VB.NET using k
eywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allo
w one to specify which classes may access any member.
Not all of the above concepts are to be found in all object-or
iented programming languages, and so object-oriented programming
that uses classes is called sometimes class-based programming.Tex
tExercises1. Answer the following question according to the text
.(1) Which programming languages can support OOP? (2) What is OOP
?(3) What is the Class of OOP? (4) What is the Object of OOP?(5)
What is the Method of OOP?2. Translate the following terms or p
hrases from English into Chinese and vice versa:keyExercises3. F
ill in the blanks with the information given in the text: (1) Man
y modern languages now support OOP.(2) One might say that a
is a blueprint or factory that describes the nature of somet
hing.(3) Some dynamic languages use double-dispatch or multi-disp
atch to find and pass . (4) Members are often specified as
, protected or private, determining whether they are avail
able to all classes, sub-classes or only the defining class.(5)
is simplifying complex reality by modeling classes appropri
ate to the problem.keyExercises 4. Choose the best one from
the items given below to complete the following passage.
Structured programming practices_(1)__rise to Pascal, in which c
onstructs were introduced to make programs more readable and bett
er _(2). C provided a combination of assembly language and high-l
evel structure to create a general-purpose language that could be
used from system to __(3)__ programming. Next came object orien
tation, which is _(4)_ of a methodology and design philosophy th
an a language issue. This is _ (5)_ by the addition of so-called
OO extensions to current languages, such as C.Exerciseskey (1
) A. giving B. given C. gave
D. gives (2) A. structure B.
structured C.constructs D.structures
(3) A. logic B. functio
C. flexible D. application (4) A. more
B. little C. a matter
D. important (5) A. evidence B. evidenced
C. evidences D. evidencingExerciseskey 5.
Mark the following statements with T(true) or F(false) according
to the text. (1) Java is not a programming language.
(2) The set of values of the attributes of a particular object
is called its member. (3) The object consists of state and
the behavior that''s defined in the object''s class. (4) In p
rogramming language, methods (sometimes referred to as "functions
") are verbs. (5) "Subclasses" are more specialized version
s of a class, which inherit attributes and behaviors from their p
arent classes, and can introduce their own.Exerciseskey 6. S
elect the one answer to each question. (1) In C program,all
variables must be before use, usually at the beginning of
the function before any executable statements。 A. stated
B. instructed C. illustrated D. declar
ed (2) When a string constant is written in C program, the
compiler creates _ of characters containing the ch
aracters of the string, and terminating it with “\0”. A. a
group B. an array C. a set D.
a series (3) OOP uses _ as data structures to enhanc
e productivity, simplify programming, and improve software reliab
ility. A. objects B. methods C.
message D. instanceExercises (4) All object orient
ed programming languages have three _ in common: object, po
lymorphism and inheritance. A.objects B. character
istics C. classes D. methods (5) OOP is
_. A. oriented- Object program B. Object-or
iented program C. oriented- Object programming D. Ob
ject-oriented programming (6) Members are often specified
as _ , protected or private. A. public B.
protect C. publish D. declareExerciseske
y 7. Translate the following sentences into Chinese.
(1) Object-oriented programming (OOP) is a programming paradigm t
hat uses "objects" – data structures consisting of data fields an
d methods together with their interactions – to design applicatio
ns and computer programs. Programming techniques may include feat
ures such as data abstraction, encapsulation, modularity, polymor
phism, and inheritance. It was not commonly used in mainstream so
ftware application development until the early 1990s. (2)
One can have an instance of a class; the instance is the actual
object created at runtime. In programmer jargon, the Lassie objec
t is an instance of the Dog class. The set of values of the attri
butes of a particular object is called its state. The object consists of state and the behavior that''s defined in the object''s class. .keyExercises (3) Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class.Exerciseskey1.略2.3. (1) programming (2) class (3)messages (4)public (5) Abstraction4. (1) C (2) B (3) D (4) A (5) B5. (1) F (2) F (3) T (4) T (5) T6. (1) D (2) B (3) A (4) B (5) D (6) A7.(1) 面向对象程序设计(OOP)是一种编程模式,使用“ 对象”设计应用程序和计算机程序。编程技术特性包括数据抽象、封装、模块化、多态特性、和继承性。90年代初之前,它不是常用的主流应用软件。现在许多现代编程语言支持面向对象编程。 (2) 我们可以有一个类的实例,该实例是对象在运行时创建的。在程序员的术语来说, Lassie对象是对Dog类的实例。一个具体对象属性的值被称作它的“状态”。对象包括状态和定义在对象类上的行为。 (3) 成员通常可以指定为公共的、保护的或私有的,来指定它们是否适用于所有类、子类或仅定义类 。
献花(0)
+1
(本文系小磊老师首藏)