c编程语言外文翻译及原文,面向对象和C语言-外文文献译文-Object-Orientation and C语言编程外文文献及中文翻译.doc...

253b171540df25e1b84436cbe50dfc72.gif面向对象和C语言-外文文献译文-Object-Orientation and C语言编程外文文献及中文翻译.doc

外文资料译文 1 外文资料原文 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 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 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, atting financial reports, controlling robots on 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 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 problem 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 programming paradigms, help us to think about problems and ulate solutions. 1. Software Design through Paradigms When designing small computer programs or large software systems, we often 外文资料译文 2 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 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 ulate solutions. We can use the mental model of 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 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 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. 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 uate expressions, and conditional branching to control the flow of cution. 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 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 外文资料译文 3 abstraction into program design. The purpose of abstraction in programming is to separate behavior from implementation. Procedures are a of abstraction. The procedure pers some task or function. Other parts of the program call the procedure, knowing that it will per the task correctly and efficiently, but without 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 provides 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 pers the above operations correctly and efficiently. Because the underlying 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 algorithm 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 defined 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 data 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 of the procedural paradigm, since procedures are still the primary for composing computations. However, rather than operate on 外文资料译文 4 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 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 object becomes a specialized version of the general object. New objects need only provide the s or data that differ because of the specialization. When an object is created or derived from another object, it is said to inherit the s and data of the parent object, and includes any new representations and new or revised s added to it. The third and final characteristic of object-oriented programming is POLYMORPHISM. Polymorphism allows many different types of objects to per the same operation by responding to the same message. For example, we may have a collection of objects which can all per 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 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 are 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 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 in them to per one of their operations. Objects are responsible for maintaining the state of their data. Only the object may modify its internal data. Objects may themselves be implemented via other 外文资料译文 5 sub-objects. Implementing an object involves a recursive process of breaking it into sub-objects until at some level the objects and s defined on them are primitives. At this point, the s and data consist of elements 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 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 that 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 s. In addition, C provides different levels of access 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. 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 interface. 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 have access to them. 外文资料译文 6 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 initialize the memory used by the object. The destructor pers any clean-up for the object when the object goes out of scope and is destroyed. Note that we didnt really hide the implementation details from the user. C does not provide a way to completely exclude all of the details of the underlying 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 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 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 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 ology, a paradigm a way of thinking about problems and finding solutions, and a of programming. As a design ology, we can use object-oriented techniques to design software systems. But it is more than a design ology, 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 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 外文资料译文 7 design and implementation cycle more seamless. Once a design has been conceived, a programming language 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 realize 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 language 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 classes, 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 objects 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 in detail. Not all class relationships dictate that inheritance be used. C provides three s of inheritance public, private, and protected. These different s are used for different relation- ships between objects. To illustrate

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值