Object-oriented programming
What is ‘‘Object-Oriented Programming’’? (1991 revised version)
Bjarne Stroustrup AT&T Bell Laboratories Murray Hill, New Jersey 07974
ABSTRACT ‘‘Object-Oriented Programming’’ and ‘‘Data Abstraction’’ have become very common terms. Unfortunately, few people agree on what they mean. I will offerinformal definitions that appear to make sense in the context of languages like Ada, C++, Modula2, Simula, and Smalltalk. The general idea is to equate ‘‘support for data abstraction’’ with the ability to define and use new types and equate ‘‘support for object-oriented programming’’ with the ability to express type hierarchies. Features necessary to support these programming styles in a generalpurpose programming language will be discussed. The presentation centers around C++ but is not limited to facilities provided by that language.
1 Introduction Not all programming languages can be ‘‘object oriented’’. Yet claims have been made to the effect that APL, Ada, Clu, C++, LOOPS, and Smalltalk are object-oriented programming languages. I have heard discussions of object-oriented design inC, Pascal, Modula-2, and CHILL. Could there somewhere be proponents of object-oriented Fortran and Cobol programming? I think there must be. ‘‘Object-oriented’’ has in many circles become a high-tech synonym for ‘‘good’’, and when you examine discussions in the trade press, you can find arguments that appear to boil down to syllogisms like: Ada is good Object oriented is good----------------------------------Ada is object oriented This paper presents one view of what ‘‘object oriented’’ ought to mean in the context of a general purpose programming language. §2 Distinguishes ‘‘object-oriented programming’’ and ‘‘data abstraction’’ from each other and from other styles of programming and presents the mechanisms that are essential for supporting the various styles of programming. §3 Presentsfeatures needed to make data abstraction effective. §4 Discusses facilities needed to support object-oriented programming. §5 Presents some limits imposed on data abstraction and object-oriented programming by traditional hardware architectures and operating systems. Examples will be presented in C++. The reason for this is partly to introduce C++ and partly because C++ is one of the few languagesthat supports both data abstraction and object-oriented programming in addition to traditional programming techniques. Issues of concurrency and of hardware support for specific higherlevel language constructs are ignored in this paper.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 - 2 - For Evaluation Only.
2 Programming Paradigms Object-oriented programming is atechnique for programming – a paradigm for writing ‘‘good’’ programs for a set of problems. If the term ‘‘object-oriented programming language’’ means anything it must mean a programming language that provides mechanisms that support the object-oriented style of programming well. There is an important distinction here. A language is said to support a style of programming if it provides facilitiesthat makes it convenient (reasonably easy, safe, and efficient) to use that style. A language does not support a technique if it takes exceptional effort or exceptional skill to write such programs; it merely enables the technique to be used. For example, you can write structured programs in Fortran, write type-secure programs in C, and use data abstraction in Modula-2, but it is unnecessarily hardto do because these languages do not support those techniques. Support for a paradigm comes not only in the obvious form of language facilities that allow direct use of the paradigm, but also in the more subtle form of compile-time and/or run-time checks against unintentional deviation from the paradigm. Type checking is the most obvious example of this; ambiguity detection and run-time checks...
Regístrate para leer el documento completo.