计算机毕业论文外文翻译---面向对象和C++.doc

上传人:来看看 文档编号:3970373 上传时间:2019-10-11 格式:DOC 页数:13 大小:59.52KB
返回 下载 相关 举报
计算机毕业论文外文翻译---面向对象和C++.doc_第1页
第1页 / 共13页
计算机毕业论文外文翻译---面向对象和C++.doc_第2页
第2页 / 共13页
计算机毕业论文外文翻译---面向对象和C++.doc_第3页
第3页 / 共13页
计算机毕业论文外文翻译---面向对象和C++.doc_第4页
第4页 / 共13页
计算机毕业论文外文翻译---面向对象和C++.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《计算机毕业论文外文翻译---面向对象和C++.doc》由会员分享,可在线阅读,更多相关《计算机毕业论文外文翻译---面向对象和C++.doc(13页珍藏版)》请在三一文库上搜索。

1、面向对象和C+C+是目前所使用的众多编程语言中的一种。为什么会有那么多的语言?为什么总会有新的语言不断出现?编程语言可以帮助程序员方便实现从设计到实现。第一个编程语言对基本的机器结构有很大的依赖性。这时程序的细节很笨重。只有硬件设计师了解如何在其他成分之外建立计算机体系,语言设计者同样认识到程序可以在一个高水平的环境编写,因而是程序员可以不必了解机器的细节。为什么有这么多高水平的编程语言?有很多语言可以访问大型数据库,格式化金融报告,控制机器人在工厂工作,处理机件,控制卫星实时模拟核反应堆,预测变化的大气层状况,下棋和绘制电路图。每一个问题都需要不同的数据结构和算法。程序语言作为一种工具帮助我

2、们解决这些问题。然而,并不是一种程序语言可以最好的解决所有问题。新的语言被开发来更好的解决一类特定的问题。其他语言可以用来解决不同的问题领域和多方面的用途。每个程序语言固定一个特定的程序体系或设计程序原理。使用多种多样的语言建立不同的设计方案。这些方案被叫做程序范例,帮助我们思考问题,规范解决。通过范例设计软件当设计一个小的计算机程序或大的软件系统是,我们要思考问题的解决模式。怎样去设计一个模式?程序范例提供了许多不同的方法去设计和思考软件系统。一个范例可以被认为是一个模式或者一个框架来设计和描述软件结构。这个模式帮助我们去思考和规范解决。我们可以选择一种语言,使用范例独立的完成。当所选择的语

3、言提供的结构和机制符合范例时,就很容易完成。一般来说,几种语言可能属于同一种范例。因此,一种范例可以被看作一种语言的类。一种语言不仅要符合一种范例,而且能够使用多种范例提供的特性和特征。混合语言,如C+,综合了两到三种范例。C+包括了命令和程序范例的特性,例如,其前身C,和面向对象范例。命令范例:命令范例的特性是计算机的抽象模型和巨大的内存存储。这是计算机体系的von Neumann模型。计算命令,由一系列的命令组成,以代码形式存储。命令可以使机器找到解决方法,使用指定命令改变存储,变量读取,算术和逻辑表达式,条件分枝控制执行流。程序范例:它包括了命令范例,还有对概念命令和表达的抽象机制。参数

4、,即存储的一部分,被引进在范例中。还包括重复,选择等特征。许多主流程序还是这种语言。程序范例在程序设计中首次引进了抽象的概念。抽象可以把动作和结果隔离。过程是抽象的表格,完成一些任务或功能。其他部分调用时,只是正确有效的执行,但不清楚过程的执行。程序范例和ADT:数据抽象使一个数据对象的行为和它的描述或执行相分离。用户无法看到数据的基本操作,执行可以方便的更改而不影响程序的运行。当我们设计一个算法时,需要一个特定的数据类型执行算法的操作。如果可以定义变量的数据类型,而不影响到实际数据类型的运行,就可以很容易的制订出算法。通过定义数据的用法和操作,假定可以选择任何一种运行,这种定义就叫做抽象数据

5、类型。抽象数据类型的使用使得算法的设计得到更大的推广,使得我们在算法设计时,注重了算法的全面,而不会拘泥于运行的细节。当算法设计完成时,实际的数据类型被执行。近来,程序语言扩展到支持新的数据类型的定义和提供便利给数据抽象。面向对象的范例:它仍然保留了许多程序范例的特征,过程仍然是计算的主要形式。但是,程序不仅仅是抽象值的运算,在面向对象范例种还有对对象的运算。对象同抽象数据类型很相似,联系着数据和运算。面向对象范例具有三种主要特性,第一种,压缩,其机制是为了实施数据抽象。第二种,继承。继承允许从已存在的对象中创建新的对象。这个新创建的对象是原对象的具体说明。新对象的不同在于只需要提供方法或数据

6、。当一个对象从另一个对象中被创建或取得时,就说新对象继承了它父对象的方法和数据,并增加了一些新的描述和说明。面向对象的第三种特性是多态。多态可以使不同类型的的对象对相同的信息执行相同的操作。例如,我们有一部分对象它们可以执行一类操作,但是只有在运行时我们才知道对象的类型。面向对象语言包含的机制确保了每一类信息传递给正确的对象。压缩,继承和多态被认为是面向对象程序的基本特征,所有的面向对象程序语言必须提供这些特征。一般来说,语言通过不同的途径支持这些特征的实现。Smalltalk, C+, Objective-C, 和 Lisp with CLOS (the Common Lisp Object

7、 System)这些程序语言都是面向对象语言的例子,它们都可以提供对压缩,继承和多态的支持。构建一个面向对象的程序需要决定解决问题所需的对象。这些对象被用来构建计算,定义软件系统的操作运行。信息的传递是对象间最基本的相互作用机制。信息(从其他的对象或程序)传递给对象,以便通知对象运行下一个操作。对象需要负责维护它所相关的数据的状态。只有对象本身才可以改变它内部的数据值。对象本身可以完全的调用它的子对象。一个对象的执行是一个循环递归的过程,当定义这个对象和方法的初始值是,可以跳出这个循环递归的过程。这时,这个方法和数据所组成的元素可以使用程序语言所提供的基本的构造函数。学习面向对象范例最重要的一

8、点是如何改变我们思考建造软件体系的思路。系统被认为是由多个单一独立的个体组成,其中每个个体只负责对其自身的操作的运行。每一个对象的设置和运行都是自身所包含的。由于对象常常模仿真实世界的个体的概念,因而这样的一个模型推动了软件方面的设计(以及后来的实行)。设计一个系统使用面向对象的范例,从而使得系统的操作和运行更类似于真实世界中所对应的真实个体。C+面向对象的特性压缩:C+继承了C的发展,并且定义的新的方便的数据类型。一个类就像C的结构,但不同的是同时包括了数据和方法。除此之外,C+还提供了类中各个成员访问权限的不同,以此方便的控制即使是在不同的类,也可以访问类中的成员。重复的调用一个抽象的数据

9、可以对用户隐藏对一个数据对象的操作细节。用户只可以通过一个公共的接口来访问这个对象。一个C+的类既包括共有的部分,又包括私有的部分。公有的部分提供给用户关于这个类的接口,私有的部分只有构造这个类的函数才可以访问。C+提供了关键字来说明类中哪些 成员是不可见的,哪些部分是其公共接口。不可见的成员在其定义的部分标明了关键字private。公共的接口部分标有关键字public。当一个类是私有的类时,意味着只有这个类的函数或友元可以使用它。一个类的定义并不分配内存。当一个数据对象被创建并且具有变量声明时才分配内存。构造函数和析构函数提供了对象的初始化和释放功能。当一个对象被声明时,它的构造函数初始化其

10、在内存的值。当对象离开它所在的范围时,调用析构函数释放对象。我们不可能对用户完全的隐藏操作的细节。C+无法提供一个使所有细节完全排除在基本操作之外的方法,因此一个类的私有部分必须这个类的定义,从而有效的访问这个类的变量,并可以继承。建造一个类可以使它方便的访问它父类的私有成员。C+定义了关键字protected来完成继承的实现。保护成员既可以被类的成员函数访问,也可以被派生类的成员函数访问。和私有成员相同的一点,保护成员不可以被用户程序访问。对象所需要注意的最后一点,信息的重复传递时对象间交流的基本功能。例如一个语句i a2.Size(),我们可以有效的把信息传给a2的对象,以确定组的大小并返

11、回其值。实际上,这里并没有真的传递信息。C+通过调用函数模拟信息的传递。编译器确保对所需要的对象调用正确的函数,因此,在C+中,可以把信息的传递当作函数的调用。当设计了一种方案,一种程序语言就可以被选择执行。可以在设计的过程中找到对象间的继承关系,甚至可以使用传统的,非面向对象的语言设计系统。但是,使用面向对象语言,如C+,由于语言支持对象间的继承关系,从而可以更方便的了解设计执行。C+语言是混合型的语言,它属于多范例的语言。C+可以认为是C语言的扩展的过程语言或面向对象语言。C+面向对象特征C+继承:任何面向对象程序语言其最主要的作用就是可以从原有的类中创建新的类,从而可以再次使用代码。继承

12、可以从与原有的类型扩展到派生类型。面向对象设计的一个主要操作就是要确认真实世界的个体以及各个个体之间的联系。当设计一个软件系统时,需要建立一系列的对象,并且需要互相关联的一系列对象。有些类之间可能不是完全的相关。大部分的类之间可以归纳为继承的关系。将一系列的类归为一个类的层次需要明白各个类之间的关系和他们之间的细节。但不是所有的类之间都可以建立继承的关系。C+提供了三种方式的继承:公有继承,私有继承,保护继承。这些不同的方式应用在不同的对象间关系。第一种关系是IS-A关系。这种关系是类型与类型,类与类之间特有的关系。IS-A继承指两个类,其中一个类描述了对对象的说明,对对象的设置说明由另一个类

13、来说明。IS-A的关系是传统的继承关系,也就是派生类型。派生类型是一些基本类型即父类型的专门化,在C+中,超级类型就是基类,派生类型就是派生类。在C+中执行IS-A关系需要使用公有继承。在基类中的公共部分使用公有继承,在派生类中也是公有的部分,在基类中的保护部分使用公有继承,在派生类中也变成保护的部分有时在两个对象之间的关系也许是包含关系,也可以是部分整体之间的关系。不是所有对象它都是其他对象的一个专门说明和继承,可能这些对象有些是其他对象的一部分或是包含在其他的对象中。在C+中使用HAS-A关系可以使用成员或是私有继承。例如,一个堆栈可以被当作一个数组使用。我们可以使用堆栈作为一个数据成员,

14、或者使用私有继承,从数组类中继承堆栈类。可以在两个类之间使用继承创建一个互相包含的关系。私有继承只有在不是接口的部分可以被使用,基类是一个细节的执行。在私有继承的情况下,原来基类中的公有部分和保护部分,在派生类中都变为私有部分。派生类的使用者不可以访问基类中的接口。但是派生类中的成员函数可以自由的访问或调用基类中的公共部分和私有部分。当这样使用基类中的成员时,用户不可以只依靠继承来编写代码。这是一个修改为不同的基类的运行。继承的另一种方式,也是很少使用的一种方式就是保护继承。保护继承也是一种可以使用HAS-A关系的继承。当使用保护继承时,在基类中的公有部分和保护部分,在派生类中就都变为保护部分

15、。当继承是接口的部分时,派生类要使用保护继承,但是不是接口的所有部分都可以被用户使用。一个保护的基类类似于一个私有的基类,不同在于继承的派生类可以知道接口部分。如果可以的话,最好使用数据成员。这时当你必须重复使用基类中的函数时,可以使用其继承。如果你所有的派生类是基类的一个说明构造时,只有使用公有继承,否则,要使用私有继承。当在不必要时使用继承,会使系统更加难以理解。总之,一个类有两个主要的接口:一个是给用户所使用的(公共接口),另一个派生类所使用(公有部分和保护部分的联合)。继承的部分是基本相同的。在基类中的公共接口使用公有继承,在派生类中队用户也是公有接口。在基类中的公共部分和保护部分使用

16、保护继承,在派生类中可以使用成员函数,但并不对派生类的所有用户。最后,当在基类中的公共部分和保护部分使用私有继承,基类可以调用,但用户和派生类不可以使用。C+多态:多态是面向对象程序的三个特性中最重要的部分。多态,和继承一起,对面向对象程序有很大的用途。多态,就是说有多个形式,提供一个基本的软件接口以建立不同类型的对象操作的统一的方式。C+提供了三种类型的多态:虚函数,函数重载和运算符重载。虚函数可以使继承的同层相关的对象用同一种方式操作。当所有的函数传递同样的信息值时,虚函数的机制确保在动态运行时了调用正确的函数。一个类的普通的成员函数是静态的单一的过程,在编译时调用。它只有一个对成员函数的

17、说明使用于类中所有的例子。当定义一个成员函数时,在它前面加上关键字virtual,实际过程的调用依赖于对象实例的类型,通过这样来判断如何调用。这是一个动态的约束。静态方式的束定也叫做早期束定。虚函数机制可以通过一个基类的参数或指针调用。一个基类的指针可以指向一个基本类型的对象或任何从基类派生出的类型的对象。虚函数也可以用在逻辑的运算上。一个类是抽象的类当这个类是继承的根节点时。一个类当它只有虚函数的定义而没有实现时是抽象类。这些函数在类定义时被赋予0值。派生类必须给出他们的实现。另一个多态的形式是函数重载。当一个函数被使用在多个程序时就是重载。重载允许在同样的名称下执行一系列相似的功能。当有相

18、同函数时,编译器通过检查它的返回值和参数决定哪个被调用。当我们定义新的数据类型时,需要定义相似类型的标准的操作。一个复数的类型要有加减的运算。我们可以使用运算符重载加减操作就像整形和浮点型数据。运算符的定义和C+函数的定义相似,可以作为类的成员或非成员。运算符有一个或两个参数分别叫做单目或双目运算符。在C+中,一个运算符函数的定义就像一个成员函数的定义,在其名字的前面加上关键字operator。C+在运算符的重载上有一些限制,只有先定义运算符的操作才可以被重载,只定义了运算符就重载是错误的。你不能把单目运算符返回到双目运算或多目运算中。同时,范围运算(:),成员运算(.*),类运算(.),选择

19、运算(?:)不能重载。在这后两点的面向对象分析中,我们可以看到C+很好的支持了面向对象的范例。Object-Orientation and C+C+ is just one of many programming languages in use today. Why are there so many languages? Why do new ones appear every few years? Programming languages have evolved to help programmers ease the transition from design to implem

20、entation. The first programming languages were very dependent on the underlying machine architecture. Writing programs at this level of detail is very cumbersome. Just as hardware engineers learned how to build computer systems out of other components, language designers also realized that programs

21、could be written at a much higher level, thereby shielding the programmer from the details of the underlying machine. Why are there such a large number of high-level programming languages? There are languages for accessing large inventory databases, formatting financial reports, controlling robots o

22、n the factory floor, processing lists, controlling satellites in real time, simulating a nuclear reactor, predicting changing atmospheric conditions, playing chess, and drawing circuit boards. Each of these problems requires different sets of data structures and algorithms. Programming languages are

23、 tools to help us solve problems. However, there is not one programming language that is best for every type of problem. New programming languages are often developed to provide better tools for solving a particular class of problems. Other languages are intended to be useful for a variety of proble

24、m domains and are more general purpose. Each programming language imparts a particular programming style or design philosophy on its programmers. With the multitude of programming languages available today, a number of such design philosophies have emerged. These design philosophies, called programm

25、ing paradigms, help us to think about problems and formulate solutions.Software Design through ParadigmsWhen designing small computer programs or large software systems, we often have a mental model of the problem we are trying to solve. How do we devise a mental model of a software system? Programm

26、ing paradigms offer many different ways of designing and thinking about software systems. A paradigm can be thought of as a mental model or as a framework for designing and describing a software systems structure. The model helps us think about and formulate solutions. We can use the mental model of

27、 a paradigm independently from the programming language chosen for implementation. However, when the chosen language provides constructs and mechanisms that are similar to those that are found in the paradigm, the implementation will be more straightforward. Usually, there are several languages that

28、 belong to a paradigm. For this reason, a programming paradigm is also considered a class of languages. A language does not have to fit into just one paradigm. More often, languages provide features or characteristics from several paradigms. Hybrid languages, such as C+, combine characteristics from

29、 two or more paradigms. C+ includes characteristics from the imperative and procedural paradigms - just like its predecessor language, C - and the object-oriented paradigm. THE IMPERATIVE PARADIGM. The imperative paradigm is characterized by an abstract model of a computer with a large memory store.

30、 This is the classic von Neumann model of computer architecture. Computations, which consist of a sequence of commands, are stored as encoding within the store. Commands enable the machine to find solutions using assignment to modify the store, variables to read the store, arithmetic and logic to ev

31、aluate expressions, and conditional branching to control the flow of execution. THE PROCEDURAL PARADIGM. The procedural paradigm includes the imperative paradigm, but extends it with an abstraction mechanism for generalizing commands and expressions into procedures. Parameters, which are essentially

32、 aliases for a portion of the store, were also introduced by this paradigm. Other features include iteration, recursion, and selection. Most mainstreams programming today is done in a procedural language. The procedural paradigm was the first paradigm to introduce the notion of abstraction into prog

33、ram design. The purpose of abstraction in programming is to separate behavior from implementation. Procedures are a form of abstraction. The procedure performs some task or function. Other parts of the program call the procedure, knowing that it will perform the task correctly and efficiently, but w

34、ithout knowing exactly how the procedure is implemented. THE PROCEDURAL PARADIGM WITH ADTs. DATA ABSTRACTION is concerned with separating the behavior of a data object from its representation or implementation. For example, a stack contains the operations Push, Pop, and IsEmpty. A stack object provi

35、des users with these operations, but does not reveal how the stack is actually implemented. The stack could be implemented using an array or a list. Users of the stack object do not care how the stack is implemented, only that it performs the above operations correctly and efficiently. Because the u

36、nderlying implementation of the data object is hidden from its users, the implementation can easily be changed without affecting the programs that use it. When we design algorithms, we often need a particular data type to use in order to carry out the algorithms operations. The design of an algorith

37、m is easier if we simply specify the data types of the variables, without worrying about how the actual data type is implemented. We describe the data type by its properties and operations and assume that whatever implementation is chosen, the operations will work correctly and efficiently. Types de

38、fined in this way are called ABSTRACT DATA TYPES (ADTs). The use of abstract data types makes the design of the algorithm more general, and allows us to concentrate on the algorithm at hand without getting bogged down in implementation details. After the algorithms have been designed, the actual dat

39、a types will need to be implemented, along with the algorithms. Recently, procedural languages have been extended to support the definition of new data types and provide facilities for data abstraction. THE OBJECT-ORIENTED PARADIGM. The object- oriented paradigm retains much of the characteristics o

40、f the procedural paradigm, since procedures are still the primary form for composing computations. However, rather than operate on abstract values, programs in the object-oriented paradigm operate on objects. An object is very similar to an abstract data type and contains data as well as procedures.

41、 There are three primary characteristics of the object-oriented paradigm. We have already described the first, ENCAPSULATION, the mechanism for enforcing data abstraction. The second characteristic is INHERITANCE. Inheritance allows new objects to be created from existing, more general ones. The new

42、 object becomes a specialized version of the general object. New objects need only provide the methods or data that differ because of the specialization. When an object is created (or derived) from another object, it is said to inherit the methods and data of the parent object, and includes any new

43、representations and new or revised methods added to it. The third and final characteristic of object-oriented programming is POLYMORPHISM. Polymorphism allows many different types of objects to perform the same operation by responding to the same message. For example, we may have a collection of obj

44、ects which can all perform a sort operation. However, we do not know what types of objects will be created until run-time. Object-oriented languages contain mechanisms for ensuring that each sort message is sent to the right object. Encapsulation, inheritance, and polymorphism are considered the fun

45、damental characteristics of object-oriented programming and all object-oriented languages must provide these characteristics in some way. Not surprisingly, languages support these characteristics in very different ways. Smalltalk, C+, Objective-C, and Lisp with CLOS (the Common Lisp Object System) a

46、re all examples of object-oriented languages, and each provides support for encapsulation, inheritance, and polymorphism. Constructing an object-oriented program involves determining the objects that are needed to solve the problem. The objects are then used to construct computations that define the

47、 behavior of the software system. Message passing is the fundamental interaction mechanism among objects. Messages (from other objects or programs) are sent to objects to inform them to perform one of their operations. Objects are responsible for maintaining the state of their data. Only the object

48、may modify its internal data. Objects may themselves be implemented via other sub-objects. Implementing an object involves a recursive process of breaking it into sub-objects until at some level the objects and methods defined on them are primitives. At this point, the methods and data consist of el

49、ements that can be implemented using the basic constructs provided by the programming language. One of the most important aspects of the object-oriented paradigm is how it changes our way of thinking about software systems. Systems are thought of as consisting of individual entities that are responsible for carrying out their own operations. Each object is conceived and implemented as self-contained. Such a model facil

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1