版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上附件一 外文原文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 implementation. The first progra
2、mming 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 could be written at a much
3、 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 on the factory floor, proce
4、ssing 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 tools to help us solve pr
5、oblems. 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 problem domains and are more gen
6、eral 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 programming paradigms, help us to
7、think about problems and formulate solutions.1. 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? Programming paradigms offer man
8、y 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 system's structure. The model helps us think about and formulate solutions. We can use the mental model of a paradigm indepe
9、ndently 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 belong to a parad
10、igm. 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 two or more parad
11、igms. 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. This is the classi
12、c 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 evaluate expressions,
13、 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 aliases for a port
14、ion 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 program design. The pur
15、pose 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 without knowing exac
16、tly 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 provides users with thes
17、e 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 underlying implement
18、ation 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 algorithm's operations. The design of an algorithm is easier if
19、 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 defined in this
20、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 data types will n
21、eed 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 of the procedur
22、al 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. There are thr
23、ee 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 object become
24、s 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 representation
25、s 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 objects which can
26、 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 fundamental chara
27、cteristics 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) are all example
28、s 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 behavior of t
29、he 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 may modify its
30、 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 elements that ca
31、n 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 carry
32、ing out their own operations. Each object is conceived and implemented as self-contained. Such a model facilitates software design (and later implementation) because objects often model conceptual real-world entities. Designing systems using the object-oriented paradigm results in software systems t
33、hat behave and appear more like their real-life counterparts. 2. The Object-Oriented Characteristics of C+ENCAPSULATION in C+. C+ extends C with a facility for defining new data types. A class is like a C struct, but contains data as well as methods. In addition, C+ provides different levels of acce
34、ss to the members of a class in order to control how the members of a class can be manipulated from outside the class. Recall that the importance of data abstraction is to hide the implementation details of a data object from the user. The user only accesses the object through its PUBLIC INTERFACE.
35、A C+ class consists of a public and private part. The public part provides the interface to the users of the class, while the private part can only be used by the functions that make up the class. C+ provides keywords to indicate which members of a class are hidden and which are part of its public i
36、nterface. The members of the hidden implementation are marked in sections beginning with the keyword private. The public interface part of the class follows the keyword public. By default, the declarations within a class are private, meaning that only the member functions (and friends) of the class
37、have access to them. A class definition does not allocate any memory. Memory is allocated when an array object is created through a variable declaration. Constructors and destructors provide the initialization and clean up of an object. When an object is declared, the constructor is called to initia
38、lize the memory used by the object. The destructor performs any clean-up for the object when the object goes out of scope and is destroyed.Note that we didn't really hide the implementation details from the user. C+ does not provide a way to completely exclude all of the details of the underlyin
39、g implementation, since the private part of the class must be included with the class definition it is useful to relax the access to variables within a class, particularly under inheritance. Often derived classes need easy access to the private members of their parent classes. C+ defines the keyword
40、 protected for this purpose. Protected members can be accessed by the member functions of a class as well as by member functions of derived classes. However, like private members, protected members cannot be accessed by user programs. One final note about objects. Recall that message passing is the
41、fundamental means for communication among objects. When we write i < a2.Size() we are effectively sending a message to the a2 array object to determine the size of the array and return it. In actuality, no message is really sent. C+ emulates message passing through the use of function calls. The
42、compiler ensures us that the correct function will be called for the desired object. So, in C+ you can think of message passing as function calls. Object-orientation has become a buzzword with many meanings. It is a design methodology, a paradigm (a way of thinking about problems and finding solutio
43、ns), and a form of programming. As a design methodology, we can use object-oriented techniques to design software systems. But it is more than a design methodology, it is a whole new way of thinking about problems. Object-oriented design allows us to think about the actual real-world entities of the
44、 problem we are attempting to provide a solution for. Beginning the design with concepts from the real- world problem domain allows the same concepts to be carried over to implementation, making the design and implementation cycle more seamless. Once a design has been conceived, a programming langua
45、ge can be chosen for implementation. By factoring out the inheritance relationships from the object hierarchies discovered during design, one can even implement the system in a traditional, non- object-oriented language. However, using an object-oriented language, such as C+, makes it easier to real
46、ize the design into an implementation because the inherent relationships among objects can be directly supported in the language. Languages such as C+ are considered hybrid languages because they are multi-paradigm languages. C+ is an object- oriented extension of C and can be used as a procedural l
47、anguage or as an object-oriented language. In this issue, we continue our tour of the object-oriented features of C+. 3. The Object-Oriented Features of C+INHERITANCE in C+. One of the major strengths of any object-oriented programming language is the ability to build other classes from existing cla
48、sses, thereby reusing code. Inheritance allows existing types to be extended to an associated collection of sub-types. Recall that one of the key actions of object-oriented design is to identify real-world entities and the relationships among them. When a software system is designed, a variety of ob
49、jects arise, which may be related in one way or another. Some classes may not be related at all. Many times it makes sense to organize the object classes into an inheritance hierarchy. Organizing a set of classes into a class hierarchy requires that we understand the relationships among the classes
50、in detail. Not all class relationships dictate that inheritance be used. C+ provides three forms of inheritance: public, private, and protected. These different forms are used for different relation- ships between objects. To illustrate these different types of inheritance, let's look at several
51、 different class relationships. The first relationship is the IS-A relationship. This type of relationship represents a specialization between types or classes. IS-A inheritance holds for two classes if the objects described by one class belongs to the set of objects described by the other more gene
52、ral class. The IS-A relationship is the traditional form of inheritance called subtyping. The subtype is a specialization of some more general type known as the supertype. In C+, the supertype is called the base class and the subtype the derived class. To implement the IS-A relationship in C+ we use
53、 public inheritance. When public inheritance is used the public parts of the base class become public in the derived class and the protected parts of the base class become protected in the derived class.To implement the HAS-A relationship in C+ we use either composition or private inheritance. For e
54、xample, a stack can be implemented using an array. We can either use the stack as a data member (composition) or derive the stack class from the array class using private inheritance. It is also possible to use inheritance to achieve a containership relationship between two classes. Private inherita
55、nce is used when the inheritance is not part of the interface; the base class is an implementation detail. Under private inheritance, the public and protected parts of the base class become part of the private part of the derived class. Users of the derived class cannot access any of the base class
56、interface. However, member functions of the derived class are free to use the public and private parts of the base class. When used this way, users cannot write code that depends on the inheritance. This is a powerful way of preserving your ability to change the implementation to a different base cl
57、ass. One other form of inheritance, which is very rarely used is protected inheritance. Protected inheritance is also used to implement HAS-A relationships. When protected inheritance is used, the public and protected parts of the base class become protected in the derived class. So, you may wish to
58、 use protected inheritance when the inheritance is part of the interface to derived classes, but not part of the interface to the users. A protected base class is almost like a private base class, except the interface is known to derived classes. It is best to use composition where possible. In case
59、s where you must override functions in a base class then by all means use inheritance. Only use public inheritance if your derived class is indeed a specialization of the base class, otherwise, private inheritance should be used. Needlessly using inheritance makes your system harder to understand. In summary, a class specifies two interfaces: one to the users of the class (the public interface) and another to implementers of derived classes (the union of public and protected parts). Inheri
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 教師師德師風(fēng)培訓(xùn)
- 四川省內(nèi)江市某校2024-2025學(xué)年高三上學(xué)期10月月考 化學(xué)試題(含答案)
- 內(nèi)蒙古通遼市科爾沁左翼中旗2024-2025學(xué)年九年級(jí)上學(xué)期期中考試數(shù)學(xué)試題
- 2024-2025學(xué)年遼寧省朝陽市建平實(shí)驗(yàn)中學(xué)高二(上)月考數(shù)學(xué)試卷(10月份)(含答案)
- 初中數(shù)學(xué)《全等三角形》八大經(jīng)典模型含答案解析
- T-ZFDSA 26-2024 赤小豆排骨湯制作標(biāo)準(zhǔn)
- 面向SDG的國網(wǎng)行動(dòng)-持續(xù)推廣港口岸電 保護(hù)綠水青山
- 信息技術(shù)(第2版)(拓展模塊)教案 拓展模塊5 5.3常用核心技術(shù)1
- 2024-2025學(xué)年八年級(jí)上學(xué)期英語期中模擬試卷(譯林版+含答案解析)
- 一年級(jí)心理健康教案
- 八年級(jí)數(shù)學(xué)上冊(cè)第一學(xué)期期中綜合測(cè)試卷(湘教版 2024年秋)
- 知道網(wǎng)課智慧《睡眠醫(yī)學(xué)(廣州醫(yī)科大學(xué))》測(cè)試答案
- T∕CSCB 0005-2021 人誘導(dǎo)多能干細(xì)胞
- 國家級(jí)燈具檢驗(yàn)報(bào)告路燈
- 兩位數(shù)乘一位數(shù)的口算課后反思
- MTBE操作規(guī)程
- 通風(fēng)網(wǎng)絡(luò)解算
- 《鴻門宴》劇本
- 天津市商品房買賣合同
- 藥物分析實(shí)驗(yàn)
- 儲(chǔ)罐安裝施工方案
評(píng)論
0/150
提交評(píng)論