%!PS %%Version: 3.3 %%DocumentFonts: (atend) %%Pages: (atend) %%EndComments % % Version 3.3 prologue for troff files. % /#copies 1 store /aspectratio 1 def /formsperpage 1 def /landscape false def /linewidth .3 def /magnification 1 def /margin 0 def /orientation 0 def /resolution 720 def /rotation 1 def /xoffset 0 def /yoffset 0 def /roundpage true def /useclippath true def /pagebbox [0 0 612 792] def /R /Times-Roman def /I /Times-Italic def /B /Times-Bold def /BI /Times-BoldItalic def /H /Helvetica def /HI /Helvetica-Oblique def /HB /Helvetica-Bold def /HX /Helvetica-BoldOblique def /CW /Courier def /CO /Courier def /CI /Courier-Oblique def /CB /Courier-Bold def /CX /Courier-BoldOblique def /PA /Palatino-Roman def /PI /Palatino-Italic def /PB /Palatino-Bold def /PX /Palatino-BoldItalic def /Hr /Helvetica-Narrow def /Hi /Helvetica-Narrow-Oblique def /Hb /Helvetica-Narrow-Bold def /Hx /Helvetica-Narrow-BoldOblique def /KR /Bookman-Light def /KI /Bookman-LightItalic def /KB /Bookman-Demi def /KX /Bookman-DemiItalic def /AR /AvantGarde-Book def /AI /AvantGarde-BookOblique def /AB /AvantGarde-Demi def /AX /AvantGarde-DemiOblique def /NR /NewCenturySchlbk-Roman def /NI /NewCenturySchlbk-Italic def /NB /NewCenturySchlbk-Bold def /NX /NewCenturySchlbk-BoldItalic def /ZD /ZapfDingbats def /ZI /ZapfChancery-MediumItalic def /S /S def /S1 /S1 def /GR /Symbol def /inch {72 mul} bind def /min {2 copy gt {exch} if pop} bind def /setup { counttomark 2 idiv {def} repeat pop landscape {/orientation 90 orientation add def} if /scaling 72 resolution div def linewidth setlinewidth 1 setlinecap pagedimensions xcenter ycenter translate orientation rotation mul rotate width 2 div neg height 2 div translate xoffset inch yoffset inch neg translate margin 2 div dup neg translate magnification dup aspectratio mul scale scaling scaling scale /Symbol /S Sdefs cf /Times-Roman /S1 S1defs cf 0 0 moveto } def /pagedimensions { useclippath userdict /gotpagebbox known not and { /pagebbox [clippath pathbbox newpath] def roundpage currentdict /roundpagebbox known and {roundpagebbox} if } if pagebbox aload pop 4 -1 roll exch 4 1 roll 4 copy landscape {4 2 roll} if sub /width exch def sub /height exch def add 2 div /xcenter exch def add 2 div /ycenter exch def userdict /gotpagebbox true put } def /pagesetup { /page exch def currentdict /pagedict known currentdict page known and { page load pagedict exch get cvx exec } if } def /decodingdefs [ {counttomark 2 idiv {y moveto show} repeat} {neg /y exch def counttomark 2 idiv {y moveto show} repeat} {neg moveto {2 index stringwidth pop sub exch div 0 32 4 -1 roll widthshow} repeat} {neg moveto {spacewidth sub 0.0 32 4 -1 roll widthshow} repeat} {counttomark 2 idiv {y moveto show} repeat} {neg setfunnytext} ] def /setdecoding {/t decodingdefs 3 -1 roll get bind def} bind def /w {neg moveto show} bind def /m {neg dup /y exch def moveto} bind def /done {/lastpage where {pop lastpage} if} def /f { dup /font exch def findfont exch dup /ptsize exch def scaling div dup /size exch def scalefont setfont linewidth ptsize mul scaling 10 mul div setlinewidth /spacewidth ( ) stringwidth pop def } bind def /changefont { /fontheight exch def /fontslant exch def currentfont [ 1 0 fontheight ptsize div fontslant sin mul fontslant cos div fontheight ptsize div 0 0 ] makefont setfont } bind def /sf {f} bind def /cf { dup length 2 idiv /entries exch def /chtab exch def /newfont exch def findfont dup length 1 add dict /newdict exch def {1 index /FID ne {newdict 3 1 roll put} {pop pop} ifelse} forall newdict /Metrics entries dict put newdict /Metrics get begin chtab aload pop 1 1 entries {pop def} for newfont newdict definefont pop end } bind def % % A few arrays used to adjust reference points and character widths in some % of the printer resident fonts. If square roots are too high try changing % the lines describing /radical and /radicalex to, % % /radical [0 -75 550 0] % /radicalex [-50 -75 500 0] % % Move braceleftbt a bit - default PostScript character is off a bit. % /Sdefs [ /bracketlefttp [201 500] /bracketleftbt [201 500] /bracketrighttp [-81 380] /bracketrightbt [-83 380] /braceleftbt [203 490] /bracketrightex [220 -125 500 0] /radical [0 0 550 0] /radicalex [-50 0 500 0] /parenleftex [-20 -170 0 0] /integral [100 -50 500 0] /infinity [10 -75 730 0] ] def /S1defs [ /underscore [0 80 500 0] /endash [7 90 650 0] ] def % % Tries to round clipping path dimensions, as stored in array pagebbox, so they % match one of the known sizes in the papersizes array. Lower left coordinates % are always set to 0. % /roundpagebbox { 7 dict begin /papersizes [8.5 inch 11 inch 14 inch 17 inch] def /mappapersize { /val exch def /slop .5 inch def /diff slop def /j 0 def 0 1 papersizes length 1 sub { /i exch def papersizes i get val sub abs dup diff le {/diff exch def /j i def} {pop} ifelse } for diff slop lt {papersizes j get} {val} ifelse } def pagebbox 0 0 put pagebbox 1 0 put pagebbox dup 2 get mappapersize 2 exch put pagebbox dup 3 get mappapersize 3 exch put end } bind def %%EndProlog %%BeginSetup mark /linewidth 0.5 def /xoffset 0 def /yoffset 0 def /#copies 1 store /magnification 1 def %%FormsPerPage: 1 /formsperpage 1 def /landscape false def /resolution 720 def setup 2 setdecoding %%EndSetup %%Page: 1 1 /saveobj save def mark 1 pagesetup 12 B f (What is ``Object-Oriented Programming''? \(1991 revised version\))6 3397 1 1181 1230 t 10 I f (Bjarne Stroustrup)1 720 1 2520 1470 t 10 R f (AT&T Bell Laboratories)2 993 1 2383 1650 t (Murray Hill, New Jersey 07974)4 1267 1 2246 1770 t 10 I f (ABSTRACT)2643 2150 w 10 R f ( have become very com-)4 1040(``Object-Oriented Programming'' and ``Data Abstraction'')4 2416 2 1224 2410 t ( will offer informal)3 801( I)1 94( few people agree on what they mean.)7 1596( Unfortunately,)1 647(mon terms.)1 462 5 1080 2530 t ( Modula-)1 374( +,)1 63( +)1 42( the context of languages like Ada, C)7 1516(definitions that appear to make sense in)6 1605 5 1080 2650 t ( abstraction'')1 539( general idea is to equate ``support for data)8 1800( The)1 216(2, Simula, and Smalltalk.)3 1045 4 1080 2770 t ( pro-)1 196(with the ability to define and use new types and equate ``support for object-oriented)13 3404 2 1080 2890 t ( support)1 338( necessary to)2 543( Features)1 402(gramming'' with the ability to express type hierarchies.)7 2317 4 1080 3010 t (these programming styles in a general purpose programming language will be discussed.)11 3600 1 1080 3130 t ( but is not limited to facilities provided by that lan-)10 2119( +)1 38( +)1 42(The presentation centers around C)4 1401 4 1080 3250 t (guage.)1080 3370 w 10 B f (1 Introduction)1 670 1 720 3730 t 10 R f ( claims have been made to the effect that)8 1717( Yet)1 205(Not all programming languages can be ``object oriented''.)7 2398 3 720 3910 t ( have heard dis-)3 655( I)1 90( are object-oriented programming languages.)4 1821( CLOS, and Smalltalk)3 908( +,)1 63( +)1 42(APL, Ada, Clu, C)3 741 7 720 4030 t ( predicted in the original version)5 1306( As)1 162( object-oriented design in C, Pascal, Modula-2, and CHILL.)8 2405(cussions of)1 447 4 720 4150 t ( ``Object-)1 419( now appearing.)2 648(of this paper, proponents of object-oriented Fortran and Cobol programming are)10 3253 3 720 4270 t ( for ``good'', and when you examine discus-)7 1856(oriented'' has in many circles become a high-tech synonym)8 2464 2 720 4390 t (sions in the trade press, you can find arguments that appear to boil down to syllogisms like:)16 3656 1 720 4510 t cleartomark saveobj restore %%BeginGlobal % % Version 3.3 drawing procedures for dpost. Automatically pulled in, but only % when needed. % /inpath false def /savematrix matrix def /Dl { inpath {pop pop neg lineto} {newpath neg moveto neg lineto stroke} ifelse } bind def /De { /y1 exch 2 div def /x1 exch 2 div def /savematrix savematrix currentmatrix def neg exch x1 add exch translate x1 y1 scale 0 0 1 0 360 inpath {1 0 moveto arc savematrix setmatrix} {newpath arc savematrix setmatrix stroke} ifelse } bind def /Da { /dy2 exch def /dx2 exch def /dy1 exch def /dx1 exch def dy1 add neg exch dx1 add exch dx1 dx1 mul dy1 dy1 mul add sqrt dy1 dx1 neg atan dy2 neg dx2 atan inpath {arc} {newpath arc stroke} ifelse } bind def /DA { /dy2 exch def /dx2 exch def /dy1 exch def /dx1 exch def dy1 add neg exch dx1 add exch dx1 dx1 mul dy1 dy1 mul add sqrt dy1 dx1 neg atan dy2 neg dx2 atan inpath {arcn} {newpath arcn stroke} ifelse } bind def /Ds { /y2 exch def /x2 exch def /y1 exch def /x1 exch def /y0 exch def /x0 exch def x0 5 x1 mul add 6 div y0 5 y1 mul add -6 div x2 5 x1 mul add 6 div y2 5 y1 mul add -6 div x1 x2 add 2 div y1 y2 add -2 div inpath {curveto} {newpath x0 x1 add 2 div y0 y1 add -2 div moveto curveto stroke} ifelse } bind def %%EndGlobal /saveobj save def mark 10 R f 2088 4672 2088 5212 Dl 3672 4672 2088 4672 Dl 3672 5212 3672 4672 Dl 2088 5212 3672 5212 Dl (Ada is good)2 483 1 2639 4782 t (Object oriented is good)3 935 1 2413 4902 t (-----------------------------------)2303 5022 w (Ada is object oriented)3 879 1 2441 5142 t (We simply)1 436 1 720 5410 t 10 I f (must)1181 5410 w 10 R f (be more careful with our concepts and logic.)7 1779 1 1395 5410 t ( mean in the context of a general pur-)8 1536(This paper presents one view of what ``object oriented'' ought to)10 2640 2 864 5530 t (pose programming language.)2 1162 1 720 5650 t ( and ``data abstraction'' from each other and from)8 2127( ``object-oriented programming'')2 1360(\2472 Distinguishes)1 689 3 864 5770 t ( for supporting the vari-)4 970(other styles of programming and presents the mechanisms that are essential)10 3062 2 1008 5890 t (ous styles of programming.)3 1094 1 1008 6010 t ( features needed to make data abstraction effective.)7 2043(\2473 Presents)1 477 2 864 6130 t ( facilities needed to support object-oriented programming.)6 2327(\2474 Discusses)1 538 2 864 6250 t ( abstraction and object-oriented programming by traditional)6 2469( some limits imposed on data)5 1230(\2475 Presents)1 477 3 864 6370 t (hardware architectures and operating systems.)4 1842 1 1008 6490 t 8 S1 f (__________________)720 6590 w 8 R f ( a version)2 313( Later,)1 229( Users' meeting in Stockholm, August 1986.)6 1434(The first version of this paper was presented at the Association of Simula)12 2344 4 720 6690 t ( first European Conference on Object-Oriented Programming in Paris and published by Springer)12 3096(was presented as an invited talk at the)7 1224 2 720 6790 t ( version has been revised to reflect the latest version)9 1678( This)1 184( issue of IEEE Software Magazine.)5 1128( also appeared in the May 1988)6 1005(Verlag. It)1 325 5 720 6890 t ( as described in)3 510( +)1 31( +)1 34(of C)1 146 4 720 6990 t 8 I f ( Reference Manual)2 615( +)1 40( +)1 43(The Annotated C)2 552 4 1466 6990 t 5 R f (5)2716 6950 w 8 R f (approved by the ANSI C++ committee \(X3J16\) as the basis of formal)11 2274 1 2766 6990 t ( \(c\) AT&T.)2 365(standardization. Copyright)1 869 2 720 7090 t cleartomark showpage saveobj restore %%EndPage: 1 1 %%Page: 2 2 /saveobj save def mark 2 pagesetup 10 R f (- 2 -)2 166 1 2797 480 t ( is)1 96( +)1 38( +)1 42( because C)2 440( and partly)2 433( +)1 38( +)1 42( reason for this is partly to introduce C)8 1567( The)1 208( +.)1 63( +)1 42(Examples will be presented in C)5 1311 12 720 840 t ( the few languages that supports both data abstraction and object-oriented programming in addition to)14 4067(one of)1 253 2 720 960 t ( specific higher-)2 676( of concurrency and of hardware support for)7 1854( Issues)1 307(traditional programming techniques.)2 1483 4 720 1080 t (level language constructs are ignored in this paper.)7 2029 1 720 1200 t 10 B f ( Paradigms)1 486(2 Programming)1 724 2 720 1440 t 10 R f ( paradigm for writing ``good'' pro-)5 1465(Object-oriented programming is a technique for programming \261 a)8 2711 2 864 1620 t ( it must)2 307( the term ``object-oriented programming language'' means anything)7 2753( If)1 120(grams for a set of problems.)5 1140 4 720 1740 t ( language that provides mechanisms that support the object-oriented style of program-)11 3464(mean a programming)2 856 2 720 1860 t (ming well.)1 428 1 720 1980 t ( language is said to)4 790( A)1 128(There is an important distinction here.)5 1556 3 864 2100 t 10 I f (support)3369 2100 w 10 R f ( of programming if it pro-)5 1070(a style)1 264 2 3706 2100 t ( language)1 389( A)1 126( efficient\) to use that style.)5 1085(vides facilities that makes it convenient \(reasonably easy, safe, and)9 2720 4 720 2220 t ( such programs; it merely)4 1037(does not support a technique if it takes exceptional effort or skill to write)13 2949 2 720 2340 t 10 I f (enables)4735 2340 w 10 R f ( can write structured programs in Fortran, write type-secure pro-)9 2571( example, you)2 565( For)1 190(the technique to be used.)4 994 4 720 2460 t ( but it is unnecessarily hard to do because these languages)10 2328(grams in C, and use data abstraction in Modula-2,)8 1992 2 720 2580 t (do not support those techniques.)4 1291 1 720 2700 t ( that allow direct use)4 860(Support for a paradigm comes not only in the obvious form of language facilities)13 3316 2 864 2820 t ( in the more subtle form of compile-time and/or run-time checks against uninten-)12 3300(of the paradigm, but also)4 1020 2 720 2940 t ( this; ambiguity detec-)3 918( checking is the most obvious example of)7 1699( Type)1 261(tional deviation from the paradigm.)4 1442 4 720 3060 t ( facilities)1 374( Extra-linguistic)1 677( used to extend linguistic support for paradigms.)7 1967(tion and run-time checks can be)5 1302 4 720 3180 t ( significant support for para-)4 1202(such as standard libraries and programming environments can also provide)9 3118 2 720 3300 t (digms.)720 3420 w ( is not necessarily better than another because it possesses a feature the other does not.)15 3703(A language)1 473 2 864 3540 t ( important issue is not so much what features a language pos-)11 2477( The)1 207( the contrary.)2 533(There are many example to)4 1103 4 720 3660 t ( styles in the)3 530(sesses but that the features it does possess are sufficient to support the desired programming)14 3790 2 720 3780 t (desired application areas:)2 1014 1 720 3900 t ( features must be cleanly and elegantly integrated into the language.)10 2714([1] All)1 272 2 864 4020 t ( solutions that would otherwise have)5 1518( must be possible to use features in combination to achieve)10 2453([2] It)1 205 3 864 4140 t (required extra separate features.)3 1272 1 1008 4260 t ( should be as few spurious and ``special purpose'' features as possible.)11 2827([3] There)1 376 2 864 4380 t ( feature should be such that its implementation does not impose significant overheads on programs)14 3960([4] A)1 216 2 864 4500 t (that do not require it.)4 841 1 1008 4620 t ( user need only know about the subset of the language explicitly used to write a program.)16 3564([5] A)1 216 2 864 4740 t ( there are any)3 572( If)1 127( principles can be summarized as ``what you don't know won't hurt you.'')12 3107(The last two)2 514 4 720 4860 t ( is)1 96( It)1 115(doubts about the usefulness of a feature it is better left out.)11 2385 3 720 4980 t 10 I f (much)3344 4980 w 10 R f (easier to add a feature to a language)7 1452 1 3588 4980 t (than to remove or modify one that has found its way into the compilers or the literature.)16 3504 1 720 5100 t ( programming styles and the key language mechanisms necessary for support-)10 3192(I will now present some)4 984 2 864 5220 t ( presentation of language features is not intended to be exhaustive.)10 2659( The)1 205(ing them.)1 378 3 720 5340 t 10 B f (Procedural Programming)1 1101 1 720 5580 t 10 R f (The original \(and probably still the most commonly used\) programming paradigm is:)11 3401 1 864 5760 t 1800 5922 1800 6282 Dl 3960 5922 1800 5922 Dl 3960 6282 3960 5922 Dl 1800 6282 3960 6282 Dl 10 I f (Decide which procedures you want;)4 1442 1 2159 6062 t (use the best algorithms you can find.)6 1469 1 2146 6182 t 10 R f ( algorithm needed to perform the desired computation.)7 2215(The focus is on the design of the processing, the)9 1961 2 864 6480 t ( by facilities for passing arguments to functions and returning values from)11 2982(Languages support this paradigm)3 1338 2 720 6600 t ( filled with discussion of ways of passing argu-)8 1951( literature related to this way of thinking is)8 1760(functions. The)1 609 3 720 6720 t ( \(procedures, rou-)2 727(ments, ways of distinguishing different kinds of arguments, different kinds of functions)11 3593 2 720 6840 t ( is the original procedural language; Algol60, Algol68, C, and Pascal are)11 3050( Fortran)1 357( etc.)1 179(tines, macros, ...\),)2 734 4 720 6960 t (later inventions in the same tradition.)5 1488 1 720 7080 t ( result.)1 279( an argument, it produces a)5 1111( Given)1 300(A typical example of ``good style'' is a square root function.)10 2486 4 864 7200 t cleartomark showpage saveobj restore %%EndPage: 2 2 %%Page: 3 3 /saveobj save def mark 3 pagesetup 10 R f (- 3 -)2 166 1 2797 480 t (To do this, it performs a well understood mathematical computation:)9 2748 1 720 840 t 9 CW f (double sqrt\(double arg\))2 1242 1 1080 1005 t ({)1080 1110 w (// the code for calculating a square root)7 2214 1 1296 1215 t (})1080 1320 w (void some_function\(\))1 1080 1 1080 1545 t ({)1080 1650 w (double root2 = sqrt\(2\);)3 1242 1 1296 1755 t (// ...)1 324 1 1296 1860 t (})1080 1965 w 10 R f (From a program organization point of view, functions are used to create order in a maze of algorithms.)17 4100 1 864 2145 t 10 B f (Data Hiding)1 526 1 720 2385 t 10 R f (Over the years, the emphasis in the design of programs has shifted away from the design of procedures)17 4176 1 864 2565 t ( set of)2 260( A)1 130( other things, this reflects an increase in program size.)9 2226( Among)1 358( data.)1 224(towards the organization of)3 1122 6 720 2685 t ( they manipulate is often called a)6 1410(related procedures with the data)4 1330 2 720 2805 t 10 I f (module)3500 2805 w 10 R f ( programming paradigm)2 1001(. The)1 245 2 3794 2805 t (becomes:)720 2925 w 1440 3087 1440 3447 Dl 4320 3087 1440 3087 Dl 4320 3447 4320 3087 Dl 1440 3447 4320 3447 Dl 10 I f (Decide which modules you want;)4 1326 1 2217 3227 t (partition the program so that data is hidden in modules.)9 2246 1 1757 3347 t 10 R f ( there is no grouping of procedures)6 1415( Where)1 318( known as the ``data hiding principle''.)6 1579(This paradigm is also)3 864 4 864 3645 t ( particular, the techniques for designing)5 1661( In)1 148(with related data the procedural programming style suffices.)7 2511 3 720 3765 t ( most common example is a defi-)6 1344( The)1 207(``good procedures'' are now applied for each procedure in a module.)10 2769 3 720 3885 t ( main problems that have to be solved are:)8 1692( The)1 205(nition of a stack module.)4 991 3 720 4005 t ( a user interface for the stack \(for example, functions)9 2110([1] Provide)1 455 2 864 4125 t 10 CW f (push\(\))3454 4125 w 10 R f (and)3839 4125 w 10 CW f (pop\(\))4008 4125 w 10 R f (\).)4308 4125 w ( \(for example, a vector of elements\) can only be accessed)10 2334( that the representation of the stack)6 1421([2] Ensure)1 421 3 864 4245 t (through this user interface.)3 1070 1 1008 4365 t ( that the stack is initialized before its first use.)9 1837([3] Ensure)1 421 2 864 4485 t (Here is a plausible external interface for a stack module:)9 2252 1 720 4605 t 9 CW f (// declaration of the interface of module stack of characters)9 3294 1 1080 4770 t (char pop\(\);)1 594 1 1080 4875 t (void push\(char\);)1 864 1 1080 4980 t (const stack_size = 100;)3 1242 1 1080 5085 t 10 R f (Assuming that this interface is found in a file called)9 2067 1 864 5265 t 10 CW f (stack.h)2956 5265 w 10 R f (, the ``internals'' can be defined like this:)7 1652 1 3376 5265 t 9 CW f (#include "stack.h")1 972 1 1080 5430 t ( ``static'' means local to this file/module)6 2322( //)1 324(static char v[stack_size];)2 1404 3 1080 5535 t ( the stack is initially empty)5 1566( //)1 702(static char* p = v;)4 1026 3 1080 5640 t (char pop\(\))1 540 1 1080 5865 t ({)1080 5970 w (// check for underflow and pop)5 1620 1 1296 6075 t (})1080 6180 w (void push\(char c\))2 918 1 1080 6405 t ({)1080 6510 w (// check for overflow and push)5 1620 1 1296 6615 t (})1080 6720 w 10 R f ( user does not)3 588( A)1 133(It would be quite feasible to change the representation of this stack to a linked list.)15 3455 3 864 6900 t ( the representation anyway \(since)4 1411(have access to)2 610 2 720 7020 t 10 CW f (v)2785 7020 w 10 R f (and)2889 7020 w 10 CW f (p)3077 7020 w 10 R f (were declared)1 574 1 3181 7020 t 10 CW f (static)3799 7020 w 10 R f (, that is, local to the)5 881 1 4159 7020 t ( a stack can be used like this:)7 1162( Such)1 250(file/module in which they were declared\).)5 1668 3 720 7140 t cleartomark showpage saveobj restore %%EndPage: 3 3 %%Page: 4 4 /saveobj save def mark 4 pagesetup 10 R f (- 4 -)2 166 1 2797 480 t 9 CW f (#include "stack.h")1 972 1 1080 885 t (void some_function\(\))1 1080 1 1080 1095 t ({)1080 1200 w (push\('c'\);)1296 1305 w (char c = pop\(\);)3 810 1 1296 1410 t (if \(c != 'c'\) error\("impossible"\);)4 1836 1 1296 1515 t (})1080 1620 w 10 R f ( grouping: the only)3 818(Pascal \(as originally defined\) doesn't provide any satisfactory facilities for such)10 3358 2 864 1800 t ( leads)1 231( This)1 229( local to a procedure.)4 843(mechanism for hiding a name from ``the rest of the program'' is to make it)14 3017 4 720 1920 t (to strange procedure nestings and over-reliance on global data.)8 2502 1 720 2040 t ( in the example above, you can define a ``module'' by grouping)11 2682( shown)1 297( As)1 172(C fares somewhat better.)3 1025 4 864 2160 t ( programmer can then control)4 1246( The)1 220( a single source file.)4 861(related function and data definitions together in)6 1993 4 720 2280 t ( the program \(a name can be seen by the rest of the program)13 2487(which names are seen by the rest of)7 1463 2 720 2400 t 10 I f (unless)4702 2400 w 10 R f (it)4984 2400 w (has been declared)2 718 1 720 2520 t 10 CW f (static)1467 2520 w 10 R f ( there)1 228( However,)1 444( in C you can achieve a degree of modularity.)9 1854(\). Consequently,)1 687 4 1827 2520 t (is no generally accepted paradigm for using this facility and the technique of relying on)14 3578 1 720 2640 t 10 CW f (static)4329 2640 w 10 R f (declara-)4720 2640 w (tions is rather low level.)4 963 1 720 2760 t ( formalizes the concept of a module, making)7 1787( It)1 112( Pascal's successors, Modula-2, goes a bit further.)7 2003(One of)1 274 4 864 2880 t ( the scopes of)3 549(it a fundamental language construct with well defined module declarations, explicit control of)12 3771 2 720 3000 t ( of generally known and accepted)5 1443(names \(import/export\), a module initialization mechanism, and a set)8 2877 2 720 3120 t (styles of usage.)2 613 1 720 3240 t ( and Modula-2 in this area can be summarized by saying that C only)13 2766(The differences between C)3 1077 2 864 3360 t 10 I f (enables)4735 3360 w 10 R f (the decomposition of a program into modules, while Modula-2)8 2512 1 720 3480 t 10 I f (supports)3257 3480 w 10 R f (that technique.)1 588 1 3627 3480 t 10 B f (Data Abstraction)1 735 1 720 3720 t 10 R f ( under the control of a type)6 1129(Programming with modules leads to the centralization of all data of a type)12 3047 2 864 3900 t ( manager module with an interface)5 1433( one wanted two stacks, one would define a stack)9 2058( If)1 126(manager module.)1 703 4 720 4020 t (like this:)1 348 1 720 4140 t 9 CW f ( stack_id is a type)4 1026( //)1 216(class stack_id;)1 810 3 1080 4305 t (// no details about stacks or stack_ids are known here)9 2916 1 1998 4410 t (stack_id create_stack\(int size\); // make a stack and return its identifier)10 3996 1 1080 4620 t ( call when stack is no longer needed)7 1944(destroy_stack\(stack_id\); //)1 1890 2 1080 4725 t (void push\(stack_id, char\);)2 1404 1 1080 4935 t (char pop\(stack_id\);)1 1026 1 1080 5040 t 10 R f (This is certainly a great improvement over the traditional unstructured mess, but ``types'' implemented this)14 4320 1 720 5220 t ( type manager module must define)5 1384( Each)1 249( the built-in types in a language.)6 1285(way are clearly very different from)5 1402 4 720 5340 t (a separate mechanism for creating ``variables'' of its type, there is no established norm for assigning object)16 4320 1 720 5460 t ( programming environment,)2 1132(identifiers, a ``variable'' of such a type has no name known to the compiler or)14 3188 2 720 5580 t (nor do such ``variables'' obey the usual scope rules or argument passing rules.)12 3135 1 720 5700 t ( aspects different from a built-in type)6 1516(A type created through a module mechanism is in most important)10 2660 2 864 5820 t ( example:)1 391( For)1 189(and enjoys support inferior to the support provided for built-in types.)10 2756 3 720 5940 t 9 CW f (void f\(\))1 432 1 1080 6105 t ({)1080 6210 w (stack_id s1;)1 648 1 1296 6315 t (stack_id s2;)1 648 1 1296 6420 t (s1 = create_stack\(200\);)2 1242 1 1296 6645 t (// Oops: forgot to create s2)5 1512 1 1296 6750 t (push\(s1,'a'\);)1296 6975 w (char c1 = pop\(s1\);)3 972 1 1296 7080 t (if \(c1 != 'a'\) error\("impossible"\);)4 1890 1 1296 7185 t cleartomark showpage saveobj restore %%EndPage: 4 4 %%Page: 5 5 /saveobj save def mark 5 pagesetup 10 R f (- 5 -)2 166 1 2797 480 t 9 CW f (push\(s2,'b'\);)1296 885 w (char c2 = pop\(s2\);)3 972 1 1296 990 t (if \(c2 != 'b'\) error\("impossible"\);)4 1890 1 1296 1095 t (destroy_stack\(s2\);)1296 1320 w (// Oops: forgot to destroy s1)5 1566 1 1296 1425 t (})1080 1530 w 10 R f ( paradigm enables this style of program-)6 1668(In other words, the module concept that supports the data hiding)10 2652 2 720 1710 t (ming, but does not support it.)5 1176 1 720 1830 t ( attack this problem by allowing a user to define types that behave)12 2670( +)1 38( +)1 42(Languages such as Ada, Clu, and C)6 1426 4 864 1950 t ( often called an)3 627( a type is)3 376( Such)1 256(in \(nearly\) the same way as built-in types.)7 1717 4 720 2070 t 10 I f (abstract data type)2 732 1 3726 2070 t 10 R f ( prefer the)2 419(\262. I)1 163 2 4458 2070 t ( are somewhat more abstract is demonstrated in the)8 2062( way of defining types that)5 1073( A)1 123(term ``user-defined type.'')2 1062 4 720 2190 t ( programming paradigm becomes:)3 1373( The)1 205(``Multiple Implementations'' subsection of \2473.)4 1879 3 720 2310 t 1620 2472 1620 2832 Dl 4140 2472 1620 2472 Dl 4140 2832 4140 2472 Dl 1620 2832 4140 2832 Dl 10 I f (Decide which types you want;)4 1198 1 2281 2612 t (provide a full set of operations for each type.)8 1802 1 1979 2732 t 10 R f (Where there is no need for more that one object of a type the data hiding programming style using mod-)19 4176 1 864 3030 t ( and complex numbers are common examples of user-)8 2314( types such as rational)4 962( Arithmetic)1 503(ules suffices.)1 541 4 720 3150 t (defined types:)1 563 1 720 3270 t 9 CW f (class complex {)2 810 1 1080 3435 t (double re, im;)2 756 1 1296 3540 t (public:)1080 3645 w (complex\(double r, double i\) { re=r; im=i; })7 2322 1 1296 3750 t ( float->complex conversion)2 1404( //)1 270(complex\(double r\) { re=r; im=0; })5 1782 3 1296 3855 t (friend complex operator+\(complex, complex\);)3 2322 1 1296 4065 t ( binary minus)2 702( //)1 270(friend complex operator-\(complex, complex\);)3 2322 3 1296 4170 t ( unary minus)2 648( //)1 756(friend complex operator-\(complex\);)2 1836 3 1296 4275 t (friend complex operator*\(complex, complex\);)3 2322 1 1296 4380 t (friend complex operator/\(complex, complex\);)3 2322 1 1296 4485 t (// ...)1 324 1 1296 4590 t (};)1080 4695 w 10 R f (The declaration of class \(that is, user-defined type\))7 2049 1 864 4875 t 10 CW f (complex)2941 4875 w 10 R f ( representation of a complex)4 1152(specifies the)1 499 2 3389 4875 t ( representation is)2 696( The)1 212(number and the set of operations on a complex number.)9 2287 3 720 4995 t 10 I f (private)3947 4995 w 10 R f ( is,)1 123(; that)1 210 2 4230 4995 t 10 CW f (re)4594 4995 w 10 R f (and)4745 4995 w 10 CW f (im)4920 4995 w 10 R f ( specified in the declaration of class)6 1466(are accessible only to the functions)5 1425 2 720 5115 t 10 CW f (complex)3642 5115 w 10 R f ( functions can be)3 697(. Such)1 281 2 4062 5115 t (defined like this:)2 672 1 720 5235 t 9 CW f (complex operator+\(complex a1, complex a2\))4 2214 1 1080 5400 t ({)1080 5505 w (return complex\(a1.re+a2.re,a1.im+a2.im\);)1 2160 1 1296 5610 t (})1080 5715 w 10 R f (and used like this:)3 725 1 864 5895 t 9 CW f (complex a = 2.3;)3 864 1 1080 6060 t (complex b = 1/a;)3 864 1 1080 6165 t (complex c = a+b*complex\(1,2.3\);)3 1674 1 1080 6270 t (// ...)1 324 1 1080 6375 t (c = -\(a/b\)+2;)2 702 1 1080 6480 t 10 R f ( concepts where the ``module)4 1196( For)1 193( user defined types.)3 788(Most, but not all, modules are better expressed as)8 1999 4 864 6660 t ( desirable even when a proper facility for defining types is available, the programmer can)14 3594(representation'' is)1 726 2 720 6780 t 8 S1 f (__________________)720 6880 w 8 R f (\262 ``)1 113 1 720 6980 t 8 I f ( they are as real as)5 618(Those types are not "abstract";)4 1001 2 833 6980 t 8 CW f (int)2474 6980 w 8 I f (and)2640 6980 w 8 CW f (float)2782 6980 w 8 I f (.)3022 6980 w 8 R f ( alternative definition of)3 775( An)1 140( Doug McIlroy.)2 502('' \261)1 134 4 3042 6980 t 8 I f (abstract data)1 425 1 4615 6980 t (types)720 7080 w 8 R f ( as types)2 280( is referred to)3 436( What)1 216(would require a mathematical ``abstract'' specification of all types \(both built-in and user-defined\).)12 3201 4 907 7080 t (in this paper would, given such a specification, be concrete specifications of such truly abstract entities.)15 3292 1 720 7180 t cleartomark showpage saveobj restore %%EndPage: 5 5 %%Page: 6 6 /saveobj save def mark 6 pagesetup 10 R f (- 6 -)2 166 1 2797 480 t ( a language might provide a module con-)7 1660( Alternatively,)1 605( of that type.)3 514(declare a type and only a single object)7 1541 4 720 840 t (cept in addition to and distinct from the class concept.)9 2159 1 720 960 t 10 B f (Problems with Data Abstraction)3 1379 1 720 1200 t 10 R f ( it has been defined, it does not really interact)9 1891( Once)1 268( of black box.)3 573(An abstract data type defines a sort)6 1444 4 864 1380 t ( new uses except by modifying its definition.)7 1806( is no way of adapting it to)7 1083( There)1 284(with the rest of the program.)5 1147 4 720 1500 t ( a type)2 312( defining)1 380( Consider)1 433(This can lead to severe inflexibility.)5 1547 4 720 1620 t 10 CW f (shape)3440 1620 w 10 R f (for use in a graphics system.)5 1252 1 3788 1620 t ( you)1 175( also that)2 363( Assume)1 373(Assume for the moment that the system has to support circles, triangles, and squares.)13 3409 4 720 1740 t (have some classes:)2 754 1 720 1860 t 9 CW f (class point{ /* ... */ };)5 1350 1 1080 2025 t (class color{ /* ... */ };)5 1350 1 1080 2130 t 10 R f (You might define a shape like this:)6 1399 1 720 2310 t 9 CW f (enum kind { circle, triangle, square };)6 2106 1 1080 2475 t (class shape {)2 702 1 1080 2685 t (point center;)1 702 1 1296 2790 t (color col;)1 540 1 1296 2895 t (kind k;)1 378 1 1296 3000 t (// representation of shape)3 1404 1 1296 3105 t (public:)1080 3210 w ( return center; })3 918( {)1 432(point where\(\))1 702 3 1296 3315 t (void move\(point to\) { center = to; draw\(\); })8 2376 1 1296 3420 t (void draw\(\);)1 648 1 1296 3525 t (void rotate\(int\);)1 918 1 1296 3630 t (// more operations)2 972 1 1296 3735 t (};)1080 3840 w 10 R f ( field'')1 282(The ``type)1 425 2 720 4020 t 10 CW f (k)1460 4020 w 10 R f (is necessary to allow operations such as)6 1634 1 1553 4020 t 10 CW f (draw\(\))3220 4020 w 10 R f (and)3613 4020 w 10 CW f (rotate\(\))3790 4020 w 10 R f (to determine what)2 737 1 4303 4020 t ( record with tag)3 644(kind of shape they are dealing with \(in a Pascal-like language, one might use a variant)15 3528 2 720 4140 t 10 CW f (k)4922 4140 w 10 R f (\).)4982 4140 w (The function)1 513 1 720 4260 t 10 CW f (draw\(\))1258 4260 w 10 R f (might be defined like this:)4 1050 1 1643 4260 t 9 CW f (void shape::draw\(\))1 972 1 1080 4425 t ({)1080 4530 w (switch \(k\) {)2 648 1 1296 4635 t (case circle:)1 648 1 1296 4740 t (// draw a circle)3 864 1 1512 4845 t (break;)1512 4950 w (case triangle:)1 756 1 1296 5055 t (// draw a triangle)3 972 1 1512 5160 t (break;)1512 5265 w (case square:)1 648 1 1296 5370 t (// draw a square)3 864 1 1512 5475 t (})1296 5580 w (})1080 5685 w 10 R f ( such as)2 328( Functions)1 451(This is a mess.)3 607 3 720 5865 t 10 CW f (draw\(\))2137 5865 w 10 R f ( There-)1 322( all the kinds of shapes there are.)7 1357(must ``know about'')2 833 3 2528 5865 t ( define a)2 357( you)1 183( If)1 124(fore the code for any such function grows each time a new shape is added to the system.)17 3656 4 720 5985 t ( are not able to add)5 777( You)1 225(new shape, every operation on a shape must be examined and \(possibly\) modified.)12 3318 3 720 6105 t ( adding a new)3 560( Since)1 273( unless you have access to the source code for every operation.)11 2515(a new shape to a system)5 972 4 720 6225 t ( operation on shapes, it requires great skill and)8 1989(shape involves ``touching'' the code of every important)7 2331 2 720 6345 t ( choice of representation of)4 1143( The)1 218( bugs into the code handling other \(older\) shapes.)8 2076(potentially introduces)1 883 4 720 6465 t ( by the requirement that \(at least some of\) their representation)10 2567(particular shapes can get severely cramped)5 1753 2 720 6585 t (must fit into the typically fixed sized framework presented by the definition of the general type)15 3797 1 720 6705 t 10 CW f (shape)4542 6705 w 10 R f (.)4842 6705 w cleartomark showpage saveobj restore %%EndPage: 6 6 %%Page: 7 7 /saveobj save def mark 7 pagesetup 10 R f (- 7 -)2 166 1 2797 480 t 10 B f (Object-Oriented Programming)1 1328 1 720 840 t 10 R f ( of any shape \(a shape has a)7 1173(The problem is that there is no distinction between the general properties)11 3003 2 864 1020 t ( a radius, is)3 473( the properties of a specific shape \(a circle is a shape that has)13 2520( and)1 201(color, it can be drawn, etc.\))5 1126 4 720 1140 t ( this distinction and taking advantage of it defines)8 2097( Expressing)1 507(drawn by a circle-drawing function, etc.\).)5 1716 3 720 1260 t ( with constructs that allows this distinction to be expressed and)10 2591( language)1 393( A)1 130(object-oriented programming.)1 1206 4 720 1380 t ( languages don't.)2 685( Other)1 277(used supports object-oriented programming.)3 1770 3 720 1500 t ( specify a class that defines the general)7 1624( First,)1 269(The Simula inheritance mechanism provides a solution.)6 2283 3 864 1620 t (properties of all shapes:)3 951 1 720 1740 t 9 CW f (class shape {)2 702 1 1080 1905 t (point center;)1 702 1 1296 2010 t (color col;)1 540 1 1296 2115 t (// ...)1 324 1 1296 2220 t (public:)1080 2325 w (point where\(\) { return center; })5 1728 1 1296 2430 t (void move\(point to\) { center = to; draw\(\); })8 2376 1 1296 2535 t (virtual void draw\(\);)2 1080 1 1296 2640 t (virtual void rotate\(int\);)2 1350 1 1296 2745 t (// ...)1 324 1 1296 2850 t (};)1080 2955 w 10 R f (The functions for which the calling interface can be defined, but where the implementation cannot be)15 4176 1 864 3135 t ( for ``may be re-)4 666( term)1 211( +)1 38( +)1 42(defined except for a specific shape, have been marked ``virtual'' \(the Simula and C)13 3363 5 720 3255 t ( this definition, we can write general functions)7 1977( Given)1 311( a class derived from this one''\).)6 1396(defined later in)2 636 4 720 3375 t (manipulating shapes:)1 847 1 720 3495 t 9 CW f (void rotate_all\(shape* v, int size, int angle\))6 2484 1 1080 3660 t (// rotate all members of vector "v" of size "size" "angle" degrees)11 3564 1 1080 3765 t ({)1080 3870 w (for \(int i = 0; i < size; i++\) v[i].rotate\(angle\);)9 2700 1 1296 3975 t (})1080 4080 w 10 R f ( its particular properties \(includ-)4 1312(To define a particular shape, we must say that it is a shape and specify)14 2864 2 864 4260 t (ing the virtual functions\).)3 1016 1 720 4380 t 9 CW f (class circle : public shape {)5 1566 1 1080 4545 t (int radius;)1 594 1 1296 4650 t (public:)1080 4755 w (void draw\(\) { /* ... */ };)6 1404 1 1296 4860 t ( yes, the null function)4 1242( //)1 324(void rotate\(int\) {})2 1026 3 1296 4965 t (};)1080 5070 w 10 R f ( class)1 219( +,)1 63( +)1 42(In C)1 175 4 720 5250 t 10 CW f (circle)1244 5250 w 10 R f (is said to be)3 475 1 1629 5250 t 10 I f (derived)2129 5250 w 10 R f (from class)1 413 1 2453 5250 t 10 CW f (shape)2891 5250 w 10 R f (, and class)2 413 1 3191 5250 t 10 CW f (shape)3629 5250 w 10 R f (is said to be a)4 548 1 3954 5250 t 10 I f (base)4528 5250 w 10 R f (of class)1 303 1 4737 5250 t 10 CW f (circle)720 5370 w 10 R f ( alternative terminology calls)3 1168(. An)1 197 2 1080 5370 t 10 CW f (circle)2470 5370 w 10 R f (and)2855 5370 w 10 CW f (shape)3024 5370 w 10 R f (subclass and superclass, respectively.)3 1494 1 3349 5370 t (The programming paradigm is:)3 1246 1 864 5490 t 1620 5652 1620 6102 Dl 4140 5652 1620 5652 Dl 4140 6102 4140 5652 Dl 1620 6102 4140 6102 Dl 10 I f (Decide which classes you want;)4 1276 1 2242 5777 t (provide a full set of operations for each class;)8 1844 1 1958 5897 t (make commonality explicit by using inheritance.)5 1936 1 1912 6017 t 10 R f ( amount of commonality between)4 1391( The)1 216(Where there is no such commonality data abstraction suffices.)8 2569 3 864 6300 t ( can be exploited by using inheritance and virtual functions is the litmus test of the applicability of)17 3933(types that)1 387 2 720 6420 t ( some areas, such as interactive graphics, there is)8 2044( In)1 144( an application area.)3 836(object-oriented programming to)2 1296 4 720 6540 t ( other areas, such as classical arithmetic)6 1707( For)1 208( programming.)1 613(clearly enormous scope for object-oriented)4 1792 4 720 6660 t (types and computations based on them, there appears to be hardly any scope for more than data abstraction)17 4320 1 720 6780 t (and the facilities needed for the support of object-oriented programming seem unnecessary\262.)11 3703 1 720 6900 t 8 S1 f (__________________)720 7000 w 8 R f ( use of inheritance: Fields are specializations of rings and vector spaces a)12 2336(\262 However, more advanced mathematics may benefit from the)8 1984 2 720 7100 t (special case of modules.)3 772 1 720 7200 t cleartomark showpage saveobj restore %%EndPage: 7 7 %%Page: 8 8 /saveobj save def mark 8 pagesetup 10 R f (- 8 -)2 166 1 2797 480 t ( commonality to)2 668( amount of)2 443( The)1 210(Finding commonality among types in a system is not a trivial process.)11 2855 4 864 840 t ( commonality must)2 785( designing a system,)3 832( When)1 295(be exploited is affected by the way the system is designed.)10 2408 4 720 960 t ( building blocks for other types, and by examin-)8 1931(be actively sought, both by designing classes specifically as)8 2389 2 720 1080 t (ing classes to see if they exhibit similarities that can be exploited in a common base class.)16 3588 1 720 1200 t ( is without recourse to specific programming)6 1816(For attempts to explain what object-oriented programming)6 2360 2 864 1320 t (language constructs see Nygaard)3 1337 1 720 1440 t 7 R f (14)2057 1390 w 10 R f (and Kerr)1 360 1 2161 1440 t 7 R f (10)2521 1390 w 10 R f ( a case study in object-oriented programming see Car-)8 2226(. For)1 223 2 2591 1440 t (gill)720 1560 w 7 R f (3)854 1510 w 10 R f (.)889 1560 w ( abstrac-)1 346(Having examined the minimum support needed for procedural programming, data hiding, data)11 3830 2 864 1680 t ( go into some detail describing features that \261 while not)10 2370(tion, and object-oriented programming we will)5 1950 2 720 1800 t (essential \261 can make data abstraction and object-oriented more effective.)9 2903 1 720 1920 t 10 B f ( for Data Abstraction)3 912(3 Support)1 476 2 720 2160 t 10 R f ( oper-)1 238(The basic support for programming with data abstraction consists of facilities for defining a set of)15 3938 2 864 2340 t ( type to that set of)5 739(ations \(functions and operators\) for a type and for restricting the access to objects of the)15 3581 2 720 2460 t ( language refinements are needed)4 1366( that is done, however, the programmer soon finds that)9 2246(operations. Once)1 708 3 720 2580 t ( overloading is a good example of this.)7 1554( Operator)1 404(for convenient definition and use of the new types.)8 2027 3 720 2700 t 10 B f (Initialization and Cleanup)2 1125 1 720 2940 t 10 R f ( for a user to initialize)5 919(When the representation of a type is hidden some mechanism must be provided)12 3257 2 864 3120 t ( simple solution is to require a user to call some function to initialize a variable)15 3296( A)1 131( that type.)2 415(variables of)1 478 4 720 3240 t ( example:)1 391( For)1 189(before using it.)2 602 3 720 3360 t 9 CW f (class vector {)2 756 1 1080 3525 t (int sz;)1 432 1 1296 3630 t (int* v;)1 378 1 1296 3735 t (public:)1080 3840 w ( call init to initialize sz and v)7 1782( //)1 270(void init\(int size\);)2 1080 3 1296 3945 t (// before the first use of a vector)7 1890 1 2538 4050 t (// ...)1 324 1 1296 4155 t (};)1080 4260 w (vector v;)1 486 1 1080 4485 t (// don't use v here)4 1026 1 1080 4590 t (v.init\(10\);)1080 4695 w (// use v here)3 702 1 1080 4800 t 10 R f ( to provide a distin-)4 819( better solution is to allow the designer of a type)10 2006( A)1 130(This is error prone and inelegant.)5 1365 4 720 4980 t ( such a function, allocation and initialization of a variable)9 2374( Given)1 302( initialization.)1 564(guished function to do the)4 1080 4 720 5100 t ( instead of two separate operations.)5 1458(becomes a single operation \(often called instantiation or construction\))8 2862 2 720 5220 t ( of a type)3 374( cases where construction of objects)5 1443( In)1 134(Such an initialization function is often called a constructor.)8 2369 4 720 5340 t ( +,)1 63( +)1 42( C)1 101( In)1 142( needs a complementary operation to clean up objects after their last use.)12 3010(is non-trivial, one often)3 962 6 720 5460 t ( a vector type:)3 568( Consider)1 411(such a cleanup function is called a destructor.)7 1818 3 720 5580 t 9 CW f (class vector {)2 756 1 1080 5745 t ( number of elements)3 1026( //)1 1296(int sz;)1 432 3 1296 5850 t ( pointer to integers)3 1080( //)1 1350(int* v;)1 378 3 1296 5955 t (public:)1080 6060 w ( constructor)1 648(vector\(int\); //)1 1728 2 1296 6165 t ( destructor)1 594(\304vector\(\); //)1 1728 2 1296 6270 t ( subscript operator)2 1026( //)1 270(int& operator[]\(int index\);)2 1458 3 1296 6375 t (};)1080 6480 w 10 R f (The)720 6660 w 10 CW f (vector)900 6660 w 10 R f (constructor can be defined to allocate space like this:)8 2112 1 1285 6660 t cleartomark showpage saveobj restore %%EndPage: 8 8 %%Page: 9 9 /saveobj save def mark 9 pagesetup 10 R f (- 9 -)2 166 1 2797 480 t 9 CW f (vector::vector\(int s\))1 1134 1 1080 885 t ({)1080 990 w (if \(s<=0\) error\("bad vector size"\);)4 1890 1 1296 1095 t (sz = s;)2 378 1 1296 1200 t ( allocate an array of "s" integers)6 1836( //)1 270(v = new int[s];)3 810 3 1296 1305 t (})1080 1410 w 10 R f (The)720 1590 w 10 CW f (vector)900 1590 w 10 R f (destructor frees the storage used:)4 1313 1 1285 1590 t 9 CW f (vector::\304vector\(\))1080 1755 w ({)1080 1860 w ( deallocate the memory pointed to by v)7 2052( //)1 594(delete v;)1 486 3 1296 1965 t (})1080 2070 w 10 R f ( for, however, by enabling a type to maintain)8 1821( is compensated)2 642( This)1 230( does not support garbage collection.)5 1480( +)1 38(C +)1 109 6 720 2250 t ( is a common use for the)6 1102( This)1 249(its own storage management without requiring intervention by a user.)9 2969 3 720 2370 t (constructor/destructor mechanism, but many uses of this mechanism are unrelated to storage management.)12 4254 1 720 2490 t 10 B f (Assignment and Initialization)2 1263 1 720 2730 t 10 R f ( can)1 171( It)1 119( and destruction of objects is sufficient for many types, but not for all.)13 2898(Controlling construction)1 988 4 864 2910 t ( class)1 219( Consider)1 411(also be necessary to control all copy operations.)7 1913 3 720 3030 t 10 CW f (vector)3288 3030 w 10 R f (:)3648 3030 w 9 CW f (vector v1\(100\);)1 810 1 1080 3195 t ( make a new vector v2 initialized to v1)8 2106( //)1 216(vector v2 = v1;)3 810 3 1080 3300 t ( assign v2 to v1)4 864( //)1 594(v1 = v2;)2 432 3 1080 3405 t 10 R f ( initialization of)2 661(It must be possible to define the meaning of the)9 1991 2 720 3585 t 10 CW f (v2)3408 3585 w 10 R f (and the assignment to)3 902 1 3564 3585 t 10 CW f (v1)4502 3585 w 10 R f (. Alterna-)1 418 1 4622 3585 t ( should be possible to prohibit such copy operations; preferably both alternatives should be avail-)14 4002(tively it)1 318 2 720 3705 t ( example:)1 391(able. For)1 380 2 720 3825 t 9 CW f (class vector {)2 756 1 1080 3990 t (int* v;)1 378 1 1296 4095 t (int sz;)1 432 1 1296 4200 t (public:)1080 4305 w (// ...)1 324 1 1296 4410 t ( assignment)1 594( //)1 216(void operator=\(const vector&\);)2 1620 3 1296 4515 t ( initialization)1 810( //)1 648(vector\(const vector&\);)1 1188 3 1296 4620 t (};)1080 4725 w 10 R f ( to interpret)2 494(specifies that user-defined operations should be used)6 2185 2 720 4905 t 10 CW f (vector)3438 4905 w 10 R f (assignment and initialization.)2 1203 1 3837 4905 t (Assignment might be defined like this:)5 1553 1 720 5025 t 9 CW f (vector::operator=\(const vector& a\) // check size and copy elements)8 3564 1 1080 5190 t ({)1080 5295 w (if \(sz != a.sz\) error\("bad vector size for ="\);)8 2538 1 1296 5400 t (for \(int i = 0; i class vector {)4 1728 3 1080 2880 t (T* v;)1 270 1 1296 2985 t (int sz;)1 378 1 1296 3090 t (public:)1080 3195 w (vector\(int s\))1 702 1 1296 3300 t ({)1296 3405 w (if \(s <= 0\) error\("bad vector size"\);)6 1998 1 1512 3510 t ( allocate an array of "s" "T"s)6 1620( //)1 324(v = new T[sz = s];)5 972 3 1512 3615 t (})1296 3720 w (T& operator[]\(int i\);)2 1134 1 1296 3825 t (int size\(\) { return sz; })5 1350 1 1296 3930 t (// ...)1 324 1 1296 4035 t (};)1080 4140 w 10 R f (A)720 4320 w 10 CW f (template)817 4320 w 10 R f (specifies a family of types generated by specifying the the templats argument\(s\).)11 3216 1 1322 4320 t (Vectors of specific types can now be defined and used:)9 2197 1 864 4440 t 9 CW f ( v1 is a vector of 100 integers)7 1674( //)1 432(vector v1\(100\);)1 1080 3 1080 4605 t ( v2 is a vector of 200 complex numbers)8 2052( //)1 216(vector v2\(200\);)1 1296 3 1080 4710 t (v2[i] = complex\(v1[x],v1[y]\);)2 1566 1 1080 4920 t 10 R f ( compared)1 420( need not be any run-time overheads)6 1458( There)1 283( support parameterized types\262.)3 1228( +)1 38( +)1 42(Ada, Clu, ML, and C)4 851 7 720 5100 t (with a class where all types involved are specified directly.)9 2356 1 720 5220 t ( exam-)1 282( For)1 197( each instantiation creates an independent type.)6 1930(A problem with parameterized types is that)6 1767 4 864 5340 t ( type)1 199(ple, the)1 297 2 720 5460 t 10 CW f (vector)1243 5460 w 10 R f (is unrelated to the type)4 918 1 1990 5460 t 10 CW f (vector)2935 5460 w 10 R f ( one would like to be)5 851(. Ideally)1 354 2 3835 5460 t ( For)1 205( from the same parameterized type.)5 1487(able to express and utilize the commonality of types generated)9 2628 3 720 5580 t (example, both)1 567 1 720 5700 t 10 CW f (vector)1313 5700 w 10 R f (and)2058 5700 w 10 CW f (vector)2227 5700 w 10 R f (have a)1 257 1 3152 5700 t 10 CW f (size\(\))3434 5700 w 10 R f (function that is independent of)4 1221 1 3819 5700 t ( to deduce this from the definition of class)8 1751( is possible, but not trivial,)5 1100( It)1 118(the parameter type.)2 781 4 720 5820 t 10 CW f (vector)4503 5820 w 10 R f (and)4896 5820 w (then allow)1 420 1 720 5940 t 10 CW f (size\(\))1166 5940 w 10 R f (to be applied to any)4 792 1 1552 5940 t 10 CW f (vector)2370 5940 w 10 R f ( \(such)1 241( interpreted or dynamically compiled language)5 1871(. An)1 198 3 2730 5940 t ( has an)2 315( +\))1 71( +)1 42( or a language supporting both parameterized types and inheritance \(such as C)12 3349(as Smalltalk\))1 543 5 720 6060 t (advantage here.)1 625 1 720 6180 t 10 B f (Exception Handling)1 855 1 720 6420 t 10 R f ( standards for handling errors \(or)5 1336(As programs grow, and especially when libraries are used extensively,)9 2840 2 864 6600 t ( each sup-)2 422( +)1 38( +)1 42( Algol68, Clu, and C)4 874( Ada,)1 251(more generally: ``exceptional circumstances''\) become important.)5 2693 6 720 6720 t (port a standard way of handling exceptions\262\262.)6 1844 1 720 6840 t 8 S1 f (__________________)720 6940 w 8 R f ( implementations support tem-)3 989( +)1 31( +)1 34( in July 1990 so only a few C)8 976( +)1 31( +)1 34( only accepted templates into C)5 1026(\262 The ANSI C++ committee, X3J16,)5 1199 8 720 7040 t (plates at the time of writing.)5 896 1 720 7140 t ( implementations that sup-)3 852( +)1 31( +)1 34( in November 1990 so C)5 793( +)1 31( +)1 34( ANSI C++ committee, X3J16, only accepted exception handling into C)10 2320(\262\262 The)1 225 8 720 7240 t cleartomark showpage saveobj restore %%EndPage: 10 10 %%Page: 11 11 /saveobj save def mark 11 pagesetup 10 R f (- 11 -)2 216 1 2772 480 t (Consider again the)2 749 1 864 840 t 10 CW f (vector)1638 840 w 10 R f (example:)2023 840 w 9 CW f (class vector {)2 756 1 1080 1005 t (// ...)1 324 1 1512 1110 t (class range { }; // type to be used for exceptions)10 2700 1 1512 1215 t (};)1080 1320 w (int& vector::operator[]\(int i\))2 1620 1 1080 1545 t ({)1080 1650 w (if \(i<0 || sz<=i\) throw range\(\);)5 1728 1 1296 1755 t (return v[i];)1 648 1 1296 1860 t (})1080 1965 w 10 R f (Instead of calling an error function,)5 1433 1 720 2145 t 10 CW f (vector::operator[]\(\))2182 2145 w 10 R f ( code,)1 243(can invoke the exception handling)4 1386 2 3411 2145 t ( to be unraveled until an exception handler for)8 1878( will cause the call stack)5 998( This)1 233(``throw the range exception.'')3 1211 4 720 2265 t 10 CW f (vector::range)720 2385 w 10 R f (is found; this handler will than be executed.)7 1748 1 1525 2385 t (An exception handler may be defined for a specific block:)9 2319 1 864 2505 t 9 CW f (void f\(int i\) {)3 810 1 1080 2670 t ( exceptions in this try block are handled by the)9 2592( //)1 918(try {)1 270 3 1296 2775 t (// exception handler defined below)4 1836 1 2376 2880 t (vector v\(i\);)1 648 1 1512 2985 t (// ...)1 324 1 1512 3090 t ( vector::range exception)2 1296( causes)1 432( //)1 486(v[i] = 7;)2 486 4 1512 3195 t (// ...)1 324 1 1512 3300 t ( might cause a vector::range exception)5 2052( //)1 324(int i = g\(\);)3 648 3 1512 3405 t (})1296 3510 w (catch \(vector::range\) {)2 1242 1 1296 3615 t (error\("f\(\): vector range error"\);)3 1782 1 1728 3720 t (return;)1728 3825 w (})1296 3930 w (})1080 4035 w 10 R f ( sketched)1 379( facility)1 312( The)1 209(There are many ways of defining exceptions and the behavior of exception handlers.)12 3420 4 720 4215 t (here resembles the ones found in Clu and ML.)8 1850 1 720 4335 t (A poor implementation of exception handling can be a serious drain on run-time efficiency and the)15 4176 1 864 4455 t ( can be implemented so that code is)7 1472( exception handling)2 804( +)1 38( +)1 42( C)1 100( The)1 213(portability of language implementations.)3 1651 7 720 4575 t ( exception is thrown or portably across C implementations by \(implicitly\) using the)12 3404(not executed unless an)3 916 2 720 4695 t (C standard library functions)3 1118 1 720 4815 t 10 CW f (setjmp\(\))1863 4815 w 10 R f (and)2368 4815 w 10 CW f (longjmp\(\))2537 4815 w 10 R f (.)3077 4815 w 10 B f (Type conversions)1 742 1 720 5055 t 10 R f ( point numbers to complex numbers)5 1561(User-defined type conversions, such as the one from floating)8 2615 2 864 5235 t ( constructor)1 482(implied by the)2 596 2 720 5355 t 10 CW f (complex\(double\))1831 5355 w 10 R f ( conver-)1 337( Such)1 258( +.)1 63( +)1 42(, have proven unexpectedly useful in C)6 1609 5 2731 5355 t ( rely on the compiler to add them implicitly where)9 2102(sions can be applied explicitly or the programmer can)8 2218 2 720 5475 t (necessary and unambiguous:)2 1148 1 720 5595 t 9 CW f (complex a = complex\(1\);)3 1242 1 1080 5760 t ( implicit: 1 -> complex\(1\))4 1404( //)1 702(complex b = 1;)3 756 3 1080 5865 t (a = b+complex\(2\);)2 918 1 1080 5970 t ( implicit: 2 -> complex\(2\))4 1404( //)1 1026(a = b+2;)2 432 3 1080 6075 t 10 R f ( because mixed mode arithmetic is the norm in lan-)9 2068( +)1 38( +)1 42( were introduced into C)4 951(User-defined type conversions)2 1221 5 720 6255 t ( types used for ``calculation'' \(for example,)6 1856(guages for numerical work and because most user-defined)7 2464 2 720 6375 t (matrices, character strings, and machine addresses\) have natural mappings to and/or from other types.)13 4063 1 720 6495 t (One use of coercions has proven especially useful from a program organization point of view:)14 3753 1 864 6615 t 8 S1 f (__________________)720 6980 w 8 R f (port exception handling are rare at the time of writing.)9 1725 1 720 7080 t cleartomark showpage saveobj restore %%EndPage: 11 11 %%Page: 12 12 /saveobj save def mark 12 pagesetup 10 R f (- 12 -)2 216 1 2772 480 t 9 CW f (complex a = 2;)3 756 1 1080 885 t ( interpreted as operator+\(a,complex\(2\)\))3 2106( //)1 216(complex b = a+2;)3 864 3 1080 990 t ( interpreted as operator+\(complex\(2\),a\))3 2106( //)1 648(b = 2+a;)2 432 3 1080 1095 t 10 R f ( interpret ``+'' operations and the two operands are handled identically by)11 3051(Only one function is needed to)5 1269 2 720 1275 t ( class)1 226( Furthermore,)1 581(the type system.)2 661 3 720 1395 t 10 CW f (complex)2220 1395 w 10 R f ( modify the concept of inte-)5 1142(is written without any need to)5 1226 2 2672 1395 t ( is in contrast to a ``pure object-)7 1292( This)1 230( smooth and natural integration of the two concepts.)8 2094(gers to enable the)3 704 4 720 1515 t (oriented system'' where the operations would be interpreted like this:)9 2776 1 720 1635 t 9 CW f ( a.operator+\(2\))1 810(a+2; //)1 540 2 1080 1800 t ( 2.operator+\(a\))1 810(2+a; //)1 540 2 1080 1905 t 10 R f ( necessary to modify class)4 1104(making it)1 394 2 720 2085 t 10 CW f (integer)2257 2085 w 10 R f (to make)1 333 1 2716 2085 t 10 CW f (2+a)3088 2085 w 10 R f ( existing code should be)4 1022(legal. Modifying)1 711 2 3307 2085 t ( object-oriented programming)2 1204( Typically,)1 461( when adding new facilities to a system.)7 1619(avoided as far as possible)4 1036 4 720 2205 t ( this case, however,)3 823( In)1 146(offers superior facilities for adding to a system without modifying existing code.)11 3351 3 720 2325 t (data abstraction facilities provide a better solution.)6 2022 1 720 2445 t 10 B f (Iterators)720 2685 w 10 R f ( of defining control)3 792(It has been claimed that a language supporting data abstraction must provide a way)13 3384 2 864 2865 t (structures)720 2985 w 7 R f (12)1108 2935 w 10 R f ( loop over the elements of some type)7 1501( particular, a mechanism that allows a user to define a)10 2198(. In)1 163 3 1178 2985 t ( be achieved without forcing a user to depend on details of)11 2392( must)1 224( This)1 232(containing elements is often needed.)4 1472 4 720 3105 t ( a sufficiently powerful mechanism for defining new)7 2181( Given)1 305( type.)1 233(the implementation of the user-defined)4 1601 4 720 3225 t ( operators, this can be handled without a separate mechanism for defining)11 3010(types and the ability to overload)5 1310 2 720 3345 t (control structures.)1 721 1 720 3465 t ( is available to a user through the)7 1400(For a vector, defining an iterator is not necessary since an ordering)11 2776 2 864 3585 t ( are several possible styles of iterators.)6 1556( There)1 284( demonstrate the technique.)3 1104( define one anyway to)4 893(indices. I'll)1 483 5 720 3705 t (My favorite relies on overloading the function application operator)8 2673 1 720 3825 t 10 CW f (\(\))3418 3825 w 10 R f (\262:)3538 3825 w 9 CW f (class vector_iterator {)2 1242 1 1080 3990 t (vector& v;)1 540 1 1296 4095 t (int i;)1 324 1 1296 4200 t (public:)1080 4305 w (vector_iterator\(vector& r\) { i = 0; v = r; })9 2376 1 1296 4410 t (int operator\(\)\(\) { return i)1 918 1 1080 4005 t (class stack {)2 702 1 1512 4110 t (public:)1512 4215 w (virtual void push\(T\) = 0; // pure virtual function)8 2700 1 1944 4320 t ( pure virtual function)3 1188( //)1 432(virtual T pop\(\) = 0;)4 1080 3 1944 4425 t (};)1512 4530 w 10 R f (The)720 4710 w 10 CW f (=0)902 4710 w 10 R f (notation specifies that no definition is required for the virtual function and that the class is abstract,)16 3991 1 1049 4710 t ( allows stacks to be used, but not created:)8 1656( This)1 228(that is, the class can only be used as a base class.)11 1949 3 720 4830 t 9 CW f (stack s; // error: stack is abstract)6 2214 1 1080 4995 t (void some_function\(stack& s, cat kitty\) // ok)6 2700 1 1080 5205 t ({)1080 5310 w (s.push\(kitty\);)1512 5415 w (cat c2 = s.pop\(\);)3 918 1 1512 5520 t (// ...)1 324 1 1512 5625 t (})1080 5730 w 10 R f ( in the stack interface, its users are totally insulated from implementa-)11 2878(Since no representation is specified)4 1442 2 720 5910 t (tion details.)1 467 1 720 6030 t ( example, we can provide a stack)6 1369( For)1 197( several distinct implementations of stacks.)5 1761(We can now provide)3 849 4 864 6150 t (implemented with an array)3 1073 1 720 6270 t cleartomark showpage saveobj restore %%EndPage: 13 13 %%Page: 14 14 /saveobj save def mark 14 pagesetup 10 R f (- 14 -)2 216 1 2772 480 t 9 CW f (template)1 918 1 1080 885 t (class astack : public stack {)5 1728 1 1512 990 t (// actual representation of a stack object)6 2268 1 1944 1095 t (// in this case an array)5 1296 1 1944 1200 t (// ...)1 324 1 1944 1305 t (public:)1512 1410 w (astack\(int size\);)1 918 1 1944 1515 t (\304astack\(\);)1944 1620 w (void push\(T\);)1 702 1 1944 1830 t (T pop\(\);)1 432 1 1944 1935 t (};)1512 2040 w 10 R f (and elsewhere a stack implemented using a linked list:)8 2175 1 720 2220 t 9 CW f (template)1 918 1 1080 2385 t (class lstack : public stack {)5 1728 1 1512 2490 t (// ...)1 324 1 1944 2595 t (};)1512 2700 w 10 R f (We can now create and use stacks:)6 1384 1 720 2880 t 9 CW f (void g\(\))1 432 1 1080 3045 t ({)1080 3150 w (lstack s1\(100\);)1 1080 1 1512 3255 t (astack s2\(100\);)1 1080 1 1512 3360 t (cat ginger;)1 594 1 1512 3585 t (cat snowball;)1 702 1 1512 3690 t (some_function\(s1,ginger\);)1512 3915 w (some_function\(s2,snowball\);)1512 4020 w (})1080 4125 w 10 R f (Only the creator of)3 882 1 720 4305 t 10 CW f (stack)1669 4305 w 10 R f (s,)1969 4305 w 10 CW f (g\(\))2100 4305 w 10 R f ( kinds of)2 436(, needs to worry about different)5 1468 2 2280 4305 t 10 CW f (stack)4252 4305 w 10 R f (s, the user)2 488 1 4552 4305 t 10 CW f (some_function\(\))720 4425 w 10 R f ( each opera-)2 490( price of this flexibility is that)6 1207( The)1 208(is totally insulated from such details.)5 1487 4 1648 4425 t (tion on such a type must be a virtual function.)9 1832 1 720 4545 t 10 B f (Implementation Issues)1 964 1 720 4785 t 10 R f ( features imple-)2 646(The support needed for data abstraction is primarily provided in the form of language)13 3530 2 864 4965 t ( are best implemented with support from a linker with)9 2156( parameterized types)2 827( However,)1 441(mented by a compiler.)3 896 4 720 5085 t ( support from the run-time)4 1124(some knowledge of the language semantics, and exception handling requires)9 3196 2 720 5205 t ( speed and effi-)3 632( can be implemented to meet the strictest criteria for both compile time)12 2907(environment. Both)1 781 3 720 5325 t (ciency without compromising generality or programmer convenience.)6 2792 1 720 5445 t ( define types increases, programs to a larger degree depend on types from libraries \(and)14 3535(As the power to)3 641 2 864 5565 t ( naturally puts greater demands on facilities to)7 1983( This)1 247( the language manual\).)3 966(not just those described in)4 1124 4 720 5685 t ( out what a library contains,)5 1165(express what is inserted into or retrieved from a library, facilities for finding)12 3155 2 720 5805 t (facilities for determining what parts of a library are actually used by a program, etc.)14 3342 1 720 5925 t ( change)1 324(For a compiled language facilities for calculating the minimal compilation necessary after a)12 3852 2 864 6045 t ( that the linker/loader \261 with suitable help from the compiler \261 is capable)13 2975( is essential)2 473( It)1 117(become important.)1 755 4 720 6165 t ( related, but)2 500(of bringing a program into memory for execution without also bringing in large amounts of)14 3820 2 720 6285 t ( particular, a library/linker/loader system that brings the code for every operation on a type)14 3637( In)1 135(unused, code.)1 548 3 720 6405 t (into core just because the programmer used one or two operations on the type is worse than useless.)17 3982 1 720 6525 t cleartomark showpage saveobj restore %%EndPage: 14 14 %%Page: 15 15 /saveobj save def mark 15 pagesetup 10 R f (- 15 -)2 216 1 2772 480 t 10 B f ( for Object-Oriented programming)3 1500(4 Support)1 476 2 720 840 t 10 R f ( a class mechanism)3 780(The basic support a programmer needs to write object-oriented programs consists of)11 3396 2 864 1020 t ( and a mechanism that allows calls of member functions to depend on the actual type of an)17 3670(with inheritance)1 650 2 720 1140 t ( design of the member function)5 1306( The)1 216( unknown at compile time\).)4 1146(object \(in cases where the actual type is)7 1652 4 720 1260 t ( supporting data abstraction techniques \(as described)6 2185( addition, facilities)2 775( In)1 147(calling mechanism is critical.)3 1213 4 720 1380 t ( data abstraction and for its refinements to support elegant)9 2384(above\) are important because the arguments for)6 1936 2 720 1500 t ( success of)2 442( The)1 210( for object-oriented programming is available.)5 1866(use of types are equally valid where support)7 1802 4 720 1620 t ( and efficiency of such types.)5 1239(both techniques hinges on the design of types and on the ease, flexibility,)12 3081 2 720 1740 t ( the ones)2 371(Object-oriented programming allows user-defined types to be far more flexible and general than)12 3949 2 720 1860 t (designed using only data abstraction techniques.)5 1931 1 720 1980 t 10 B f (Calling Mechanisms)1 870 1 720 2220 t 10 R f ( which a mem-)3 614(The key language facility supporting object-oriented programming is the mechanism by)10 3562 2 864 2400 t ( example, given a pointer)4 1020( For)1 191( invoked for a given object.)5 1108(ber function is)2 583 4 720 2520 t 10 CW f (p)3649 2520 w 10 R f (, how is a call)4 560 1 3709 2520 t 10 CW f (p->f\(arg\))4296 2520 w 10 R f (han-)4863 2520 w ( is a range of choices.)5 864(dled? There)1 498 2 720 2640 t ( and Simula, where static type checking is extensively used, the type system)12 3149( +)1 38( +)1 42(In languages such as C)4 947 4 864 2760 t ( two alternatives are available:)4 1219( +,)1 63( +)1 42( C)1 92( In)1 133(can be employed to select between different calling mechanisms.)8 2597 6 720 2880 t ( called is determined at compile time \(through a)8 1970( normal function call: the member function to be)8 1990([1] A)1 216 3 864 3000 t ( and called using the standard function call mechanism with)9 2421(lookup in the compiler's symbol tables\))5 1611 2 1008 3120 t ( the ``standard)2 608( Where)1 331( the function is called.)4 949(an argument added to identify the object for which)8 2144 4 1008 3240 t ( enough, the programmer can declare a function)7 1967(function call'' is not considered efficient)5 1672 2 1008 3360 t 10 CW f (inline)4680 3360 w 10 R f ( this way, one can achieve the efficiency)7 1645( In)1 137( will attempt to inline expand its body.)7 1573(and the compiler)2 677 4 1008 3480 t ( optimization is)2 635( This)1 234( function semantics.)2 814(of a macro expansion without compromising the standard)7 2349 4 1008 3600 t (equally valuable as a support for data abstraction.)7 1979 1 1008 3720 t ( The function to be called depends on the type of the object for which it is)16 3095( virtual function call:)3 865([2] A)1 216 3 864 3840 t ( the pointer)2 459( Typically,)1 460( general be determined until run time.)6 1518( type cannot in)3 600(called. This)1 494 5 1008 3960 t 10 CW f (p)4566 3960 w 10 R f (will be of)2 387 1 4653 3960 t (some base class)2 636 1 1008 4080 t 10 CW f (B)1671 4080 w 10 R f ( be an object of some derived class)7 1415(and the object will)3 747 2 1758 4080 t 10 CW f (D)3948 4080 w 10 R f (\(as was the case with the)5 1004 1 4036 4080 t (base class)1 406 1 1008 4200 t 10 CW f (shape)1449 4200 w 10 R f (and the derived class)3 864 1 1784 4200 t 10 CW f (circle)2682 4200 w 10 R f ( call mechanism must look into the)6 1454(above\). The)1 510 2 3076 4200 t ( the compiler to determine which function)6 1723(object and find some information placed there by)7 2008 2 1008 4320 t 10 CW f (f)4771 4320 w 10 R f (is to)1 177 1 4863 4320 t ( is found, say)3 557( that function)2 551( Once)1 269(be called.)1 391 4 1008 4440 t 10 CW f (D::f)2809 4440 w 10 R f (, it can be called using the mechanism described)8 1991 1 3049 4440 t ( name)1 245(above. The)1 472 2 1008 4560 t 10 CW f (f)1754 4560 w 10 R f ( compile time converted into an index into a table of pointers to functions.)13 3029(is at)1 168 2 1843 4560 t ( the ``normal function call'')4 1186(This virtual call mechanism can be made essentially as efficient as)10 2846 2 1008 4680 t ( implementation, only five additional memory references are used.)8 2656( +)1 38( +)1 42( the standard C)3 602(mechanism. In)1 613 5 1008 4800 t ( is)1 99( What)1 273( weak static type checking a more elaborate mechanism must be employed.)11 3082(In languages with)2 722 4 864 4920 t ( the names of all member functions \(methods\) of a class)10 2235(done in a language like Smalltalk is to store a list of)11 2085 2 720 5040 t (so that they can be found at run time:)8 1487 1 720 5160 t ( table of method names is found by examining the object)10 2310([3] A method invocation: First the appropriate)6 1866 2 864 5280 t (pointed to by)2 532 1 1008 5400 t 10 CW f (p)1567 5400 w 10 R f ( this table \(or set of tables\) the string)8 1481(. In)1 160 2 1627 5400 t 10 CW f ("f")3295 5400 w 10 R f ( object has an)3 549(is looked up to see if the)6 989 2 3502 5400 t 10 CW f (f\(\))1008 5520 w 10 R f ( an)1 120(. If)1 142 2 1188 5520 t 10 CW f (f\(\))1476 5520 w 10 R f ( lookup differs)2 592( This)1 230( some error handling takes place.)5 1329(is found it is called; otherwise)5 1207 4 1682 5520 t ( invocation)1 448(from the lookup done at compile time in a statically checked language in that the method)15 3584 2 1008 5640 t (uses a method table for the actual object.)7 1630 1 1008 5760 t ( static)1 248( Since)1 284( with a virtual function call, but more flexible.)8 1944(A method invocation is inefficient compared)5 1844 4 720 5880 t ( arguments typically cannot be done for a method invocation, the use of methods must be)15 3643(type checking of)2 677 2 720 6000 t (supported by dynamic type checking.)4 1495 1 720 6120 t 10 B f (Type Checking)1 648 1 720 6360 t 10 R f ( in addition to this, does a method)7 1440( What,)1 303(The shape example showed the power of virtual functions.)8 2433 3 864 6540 t ( can attempt to invoke)4 888( You)1 222(invocation mechanism do for you?)4 1387 3 720 6660 t 10 I f (any)3242 6660 w 10 R f (method for)1 441 1 3411 6660 t 10 I f (any)3877 6660 w 10 R f (object.)4046 6660 w ( purpose libraries to)3 838(The ability to invoke any method for any object enables the designer of general)13 3338 2 864 6780 t ( the design of libraries.)4 958( this simplifies)2 612( Naturally)1 438(push the responsibility for handling types onto the user.)8 2312 4 720 6900 t (However, it then becomes the responsibility of the user to avoid type mismatches like this:)14 3622 1 720 7020 t cleartomark showpage saveobj restore %%EndPage: 15 15 %%Page: 16 16 /saveobj save def mark 16 pagesetup 10 R f (- 16 -)2 216 1 2772 480 t 9 CW f (// assume dynamic type checking.)4 1728 1 1080 885 t (// *** NOT C++ ***)4 972 1 1080 990 t ( Stack can hold pointers to objects of any type)9 2538( //)1 216(Stack s;)1 432 3 1080 1200 t (cs.push\(new Saab900\);)1 1134 1 1080 1410 t (cs.push\(new Saab37B\);)1 1134 1 1080 1515 t ( fine: a Saab37B is a plane)6 1458(cs.pop\(\)->takeoff\(\); //)1 1350 2 1080 1725 t ( Oops! Run time error: a Saab 900 is a car)10 2268(cs.pop\(\)->takeoff\(\); //)1 1350 2 1080 1935 t (// a car does not have a takeoff method.)8 2160 1 2322 2040 t 10 R f (An attempt to use a)4 793 1 864 2220 t 10 CW f (car)1687 2220 w 10 R f (as a)1 157 1 1897 2220 t 10 CW f (plane)2084 2220 w 10 R f (will be detected by the message handler and an appropriate error)10 2626 1 2414 2220 t ( The)1 217( is also the programmer.)4 1016( that is only a consolation when the user)8 1708( However,)1 453(handler will be called.)3 926 5 720 2340 t ( this class are not present in sys-)7 1304(absence of static type checking makes it difficult to guarantee that errors of)12 3016 2 720 2460 t (tems delivered to end-users.)3 1120 1 720 2580 t ( use of virtual functions can approach the flexibility, ease)9 2299(Combinations of parameterized classes and the)5 1877 2 864 2700 t ( of use of libraries designed with method lookup without relaxing the static type check-)14 3546(of design, and ease)3 774 2 720 2820 t ( example:)1 391( For)1 189(ing or incurring significant run time overheads \(in time or space\).)10 2615 3 720 2940 t 9 CW f (stack cs;)1 918 1 1080 3105 t ( Compile time error:)3 1080( //)1 324(cs.push\(new Saab900\);)1 1134 3 1080 3315 t (// type mismatch: car* passed, plane* expected)6 2484 1 2430 3420 t (cs.push\(new Saab37B\);)1 1134 1 1080 3525 t ( fine: a Saab 37B is a plane)7 1512(cs.pop\(\)->takeoff\(\); //)1 1836 2 1080 3735 t (cs.pop\(\)->takeoff\(\);)1080 3840 w 10 R f ( a somewhat different style of program-)6 1639(The use of static type checking and virtual function calls leads to)11 2681 2 720 4020 t ( class speci-)2 490( +)1 38( +)1 42( Simula or C)3 521( example, a)2 467( For)1 194(ming than does dynamic type checking and method invocation.)8 2568 7 720 4140 t ( fixed interface to a set of objects \(of any derived class\) whereas a Smalltalk class specifies an initial)18 4103(fies a)1 217 2 720 4260 t ( other words, a Smalltalk class is a minimal specification)9 2312( In)1 138(set of operations for objects \(of any subclass\).)7 1870 3 720 4380 t ( class is an exact specification and the user)8 1731( +)1 38( +)1 42( a C)2 167(and the user is free to try operations not specified whereas)10 2342 5 720 4500 t (is guaranteed that only operations specified in the class declaration will be accepted by the compiler.)15 4020 1 720 4620 t 10 B f (Inheritance)720 4860 w 10 R f ( some form of method lookup without having an inheritance mechanism.)10 3031(Consider a language having)3 1145 2 864 5040 t ( you could do)3 571( Clearly,)1 378( think not.)2 427( I)1 92(Could that language be said to support object-oriented programming?)8 2852 5 720 5160 t ( to)1 120( However,)1 457( to suit conditions.)3 791(interesting things with the method table to adapt the objects' behavior)10 2952 4 720 5280 t ( of associating methods and the data structures they assume)9 2377(avoid chaos, there must be some systematic way)7 1943 2 720 5400 t ( enable a user of an object to know what kind of behavior to expect, there)15 2947( To)1 162(for their object representation.)3 1211 3 720 5520 t ( different behaviors the)3 967(would also have to be some standard way of expressing what is common to the)14 3353 2 720 5640 t ( ``systematic and standard way'' would be an inheritance mechanism.)9 2788( This)1 228(object might adopt.)2 775 3 720 5760 t ( that)1 177( Could)1 297( methods.)1 391(Consider a language having an inheritance mechanism without virtual functions or)10 3311 4 864 5880 t ( think not: the shape example does not have a)9 1862( I)1 88( programming?)1 618(language be said to support object-oriented)5 1752 4 720 6000 t ( more powerful than a)4 925( such a language would be noticeably)6 1557( However,)1 450(good solution in such a language.)5 1388 4 720 6120 t ( is supported by the observation that many Simula and)9 2219( contention)1 453( This)1 234(``plain'' data abstraction language.)3 1414 4 720 6240 t ( ability to express com-)4 966( The)1 212( structured using class hierarchies without virtual functions.)7 2435( programs are)2 560( +)1 38(C +)1 109 6 720 6360 t ( example, the problems associated with the need to)8 2065( For)1 193( tool.)1 210(monality \(factoring\) is an extremely powerful)5 1852 4 720 6480 t ( in the)2 258( However,)1 444( be needed.)2 459( union would)2 534( No)1 175(have a common representation of all shapes could be solved.)9 2450 6 720 6600 t ( use of ``type fields'' to determine)6 1387(absence of virtual functions, the programmer would have to resort to the)11 2933 2 720 6720 t (actual types of objects, so the problems with the lack of modularity of the code would remain\262.)16 3806 1 720 6840 t ( It)1 122( programming tool in its own right.)6 1475(This implies that class derivation \(subclassing\) is an important)8 2579 3 864 6960 t 8 S1 f (__________________)720 7060 w 8 R f (\262 This is the problem with Simula's)6 1142 1 720 7160 t 8 CW f (inspect)1882 7160 w 8 R f ( +.)1 51( +)1 34(statement and the reason it does not have a counterpart in C)11 1897 3 2238 7160 t cleartomark showpage saveobj restore %%EndPage: 16 16 %%Page: 17 17 /saveobj save def mark 17 pagesetup 10 R f (- 17 -)2 216 1 2772 480 t ( is particularly true if one)5 1042( This)1 234( object-oriented programming, but it has wider uses.)7 2131(can be used to support)4 913 4 720 840 t ( in object-oriented programming with the idea that a base class expresses a)12 3043(identifies the use of inheritance)4 1277 2 720 960 t ( idea captures only part of the expres-)7 1525( This)1 231(general concept of which all derived classes are specializations.)8 2564 3 720 1080 t ( encouraged by languages where every member function is vir-)9 2563(sive power of inheritance, but it is strongly)7 1757 2 720 1200 t ( controls of what is inherited \(see Snyder)7 1772( suitable)1 354( Given)1 312(tual \(or a method\).)3 797 4 720 1320 t 7 R f (18)3955 1270 w 10 R f (and Stroustrup)1 605 1 4069 1320 t 7 R f (19)4674 1270 w 10 R f (\), class)1 296 1 4744 1320 t ( a class, derivation can be used to add)8 1617( Given)1 308( types.)1 275(derivation can be a powerful tool for creating new)8 2120 4 720 1440 t ( resulting class to its base cannot always be completely)9 2425( relation of the)3 657( The)1 229(and/or subtract features.)2 1009 4 720 1560 t (described in terms of specialization; factoring may be a better term.)10 2697 1 720 1680 t ( a programmer and there is no foolproof way of predicting how)11 2536(Derivation is another tool in the hands of)7 1640 2 864 1800 t ( uses are sim-)3 552(it is going to be used \261 and it is too early \(even after almost 25 years of Simula\) to tell which)21 3768 2 720 1920 t (ply mis-uses.)1 528 1 720 2040 t 10 B f (Multiple Inheritance)1 886 1 720 2280 t 10 R f (When a class)2 532 1 864 2460 t 10 CW f (A)1424 2460 w 10 R f ( class)1 223(is a base of)3 455 2 1512 2460 t 10 CW f (B)2219 2460 w 10 R f (, a)1 98 1 2279 2460 t 10 CW f (B)2406 2460 w 10 R f (inherits the attributes of an)4 1087 1 2495 2460 t 10 CW f (A)3611 2460 w 10 R f (; that is, a)3 401 1 3671 2460 t 10 CW f (B)4101 2460 w 10 R f (is an)1 190 1 4190 2460 t 10 CW f (A)4409 2460 w 10 R f (in addition to)2 542 1 4498 2460 t ( might be useful to have a class)7 1265( this explanation it seems obvious that it)7 1630( Given)1 297(whatever else it might be.)4 1041 4 720 2580 t 10 CW f (B)4980 2580 w 10 R f (inherit from two base classes)4 1159 1 720 2700 t 10 CW f (A1)1904 2700 w 10 R f (and)2049 2700 w 10 CW f (A2)2218 2700 w 10 R f ( is called multiple inheritance)4 1182(. This)1 253 2 2338 2700 t 7 R f (23)3773 2650 w 10 R f (.)3843 2700 w ( library classes)2 619(A fairly standard example of the use of multiple inheritance would be to provide two)14 3557 2 864 2820 t 10 CW f (displayed)720 2940 w 10 R f (and)1298 2940 w 10 CW f (task)1480 2940 w 10 R f (for representing objects under the control of a display manager and co-routines)11 3283 1 1757 2940 t ( programmer could then create classes such as)7 1842( A)1 122(under the control of a scheduler, respectively.)6 1823 3 720 3060 t 9 CW f (class my_displayed_task : public displayed, public task {)7 3078 1 1080 3225 t (// my stuff)2 594 1 1296 3330 t (};)1080 3435 w ( not displayed)2 756( //)1 216(class my_task : public task {)5 1566 3 1080 3660 t (// my stuff)2 594 1 1296 3765 t (};)1080 3870 w ( not a task)3 594( //)1 216(class my_displayed : public displayed {)5 2106 3 1080 4095 t (// my stuff)2 594 1 1296 4200 t (};)1080 4305 w 10 R f ( This)1 240( be open to the programmer.)5 1191(Using \(only\) single inheritance only two of these three choices would)10 2889 3 720 4485 t ( this example can be han-)5 1042( +)1 38( +)1 42( C)1 98( In)1 139(leads to either code replication or loss of flexibility \261 and typically both.)12 2961 6 720 4605 t ( inheritance and)2 643(dled as shown above with to no significant overheads \(in time or space\) compared to single)15 3677 2 720 4725 t (without sacrificing static type checking)4 1570 1 720 4845 t 7 R f (20)2290 4795 w 10 R f (.)2360 4845 w (Ambiguities are handled at compile time:)5 1657 1 864 4965 t 9 CW f (class A { public: void f\(\); /* ... */ };)9 2160 1 1080 5130 t (class B { public: void f\(\); /* ... */ };)9 2160 1 1080 5235 t (class C : public A, public B { /* ... */ };)11 2322 1 1080 5340 t (void g\(C* p\))2 648 1 1080 5550 t ({)1080 5655 w (p->f\(\); // error: ambiguous)3 1458 1 1512 5760 t (})1080 5865 w 10 R f ( these Lisp)2 453( In)1 143( inheritance.)1 503( differs from the object-oriented Lisp dialects that support multiple)9 2753( +)1 38( +)1 42(In this, C)2 388 7 720 6045 t ( the order of declarations significant, by considering objects)8 2393(dialects ambiguities are resolved by considering)5 1927 2 720 6165 t ( methods of the same name in base)7 1465(of the same name in different base classes identical, or by combining)11 2855 2 720 6285 t (classes into a more complex method of the highest class.)9 2264 1 720 6405 t ( one would typically resolve the ambiguity by adding a function:)10 2587( +,)1 63( +)1 42(In C)1 175 4 864 6525 t cleartomark showpage saveobj restore %%EndPage: 17 17 %%Page: 18 18 /saveobj save def mark 18 pagesetup 10 R f (- 18 -)2 216 1 2772 480 t 9 CW f (class C : public A, public B {)7 1620 1 1080 885 t (// ...)1 324 1 1512 990 t (public:)1080 1095 w (void f\(\);)1 486 1 1512 1200 t (// ...)1 324 1 1512 1305 t (};)1080 1410 w (void f\(\))1 432 1 1080 1635 t ({)1080 1740 w (// C's own stuff)3 864 1 1512 1845 t (A::f\(\);)1512 1950 w (B::f\(\);)1512 2055 w (})1080 2160 w 10 R f ( appears to be a)4 680(In addition to this straightforward concept of independent multiple inheritance there)10 3496 2 864 2340 t ( a multiple inheritance)3 911(need for a more general mechanism for expressing dependencies between classes in)11 3409 2 720 2460 t ( sub-object should be shared by all other sub-objects in a class object)12 2805( the requirement that a)4 910( +,)1 63( +)1 42( C)1 95(lattice. In)1 405 6 720 2580 t (is expressed through the mechanism of a virtual base class:)9 2360 1 720 2700 t 9 CW f (class W { /* ... */ }; // window)8 1728 1 1080 2865 t (class Bwindow: public virtual W { // window with border)9 2970 1 1080 3075 t (// ...)1 324 1 1512 3180 t (};)1080 3285 w (class Mwindow : public virtual W { // window with menu)10 2916 1 1080 3510 t (// ...)1 324 1 1512 3615 t (};)1080 3720 w (class BMW : public Bwindow, public Mwindow {)7 2376 1 1080 3945 t (// window with border and menu)5 1620 1 1512 4050 t (// ...)1 324 1 1512 4155 t (};)1080 4260 w 10 R f (Here the \(single\))2 672 1 720 4440 t 10 CW f (window)1418 4440 w 10 R f (sub-object is shared by the)4 1069 1 1804 4440 t 10 CW f (Bwindow)2900 4440 w 10 R f (and)3347 4440 w 10 CW f (Bwindow)3518 4440 w 10 R f (sub-objects of a)2 636 1 3965 4440 t 10 CW f (BMW)4628 4440 w 10 R f (. The)1 232 1 4808 4440 t ( using such complicated class)4 1210(Lisp dialects provide concepts of method combination to ease programming)9 3110 2 720 4560 t ( does not.)2 386( +)1 38( +)1 42(hierarchies. C)1 579 4 720 4680 t 10 B f (Encapsulation)720 4920 w 10 R f ( a function member\) that needs to be protected from)9 2130(Consider a class member \(either a data member or)8 2046 2 864 5100 t ( the set of functions that may access)7 1446( choices can be reasonable for delimiting)6 1647( What)1 268(``unauthorized access.'')1 959 4 720 5220 t ( ``obvious'' answer for a language supporting object-oriented programming is ``all oper-)11 3567( The)1 206(that member?)1 547 3 720 5340 t ( non-obvious implication of this answer is)6 1713( A)1 128(ations defined for this object,'' that is, all member functions.)9 2479 3 720 5460 t ( since)1 239(that there cannot be a complete and final list of all functions that may access the protected member)17 4081 2 720 5580 t ( from the protected member's class and define a mem-)9 2211(one can always add another by deriving a new class)9 2109 2 720 5700 t ( large degree of protection from accident)6 1736( approach combines a)3 918( This)1 245(ber function of that derived class.)5 1421 4 720 5820 t ( the flexibility needed for ``tool)5 1312(\(since you do not easily define a new derived class ``by accident''\) with)12 3008 2 720 5940 t ( by deriving)2 489(building'' using class hierarchies \(since you can ``grant yourself access'' to protected members)12 3831 2 720 6060 t ( example:)1 391( For)1 189(a class\).)1 321 3 720 6180 t 9 CW f (class Window {)2 756 1 1080 6345 t (// ...)1 324 1 1512 6450 t (protected:)1080 6555 w (Rectangle inside;)1 918 1 1512 6660 t (// ...)1 324 1 1512 6765 t (public:)1080 6870 w (// ...)1 324 1 1512 6975 t (};)1080 7080 w cleartomark showpage saveobj restore %%EndPage: 18 18 %%Page: 19 19 /saveobj save def mark 19 pagesetup 10 R f (- 19 -)2 216 1 2772 480 t 9 CW f (class Dumb_terminal : Window {)4 1620 1 1080 885 t (// ...)1 324 1 1512 990 t (public:)1080 1095 w (void prompt\(\);)1 756 1 1512 1200 t (// ...)1 324 1 1512 1305 t (};)1080 1410 w 10 R f (Here)720 1590 w 10 CW f (Window)938 1590 w 10 R f (specifies)1323 1590 w 10 CW f (inside)1697 1590 w 10 R f (as protected so that derived classes such as)7 1710 1 2082 1590 t 10 CW f (Dumb_terminal)3817 1590 w 10 R f (can read it)2 417 1 4623 1590 t (and figure out what part of the)6 1214 1 720 1710 t 10 CW f (Window)1959 1710 w 10 R f ('s area it may manipulate.)4 1034 1 2319 1710 t ( towards data abstraction is different: ``list)6 1709(Unfortunately, the ``obvious'' answer for a language oriented)7 2467 2 864 1830 t ( In)1 137( is nothing special about these functions.)6 1648( There)1 286( access in the class declaration.'')5 1327(the functions that need)3 922 5 720 1950 t ( private class mem-)3 797( non-member function with access to)5 1503( A)1 127(particular, they need not be member functions.)6 1893 4 720 2070 t (bers is called a)3 599 1 720 2190 t 10 CW f (friend)1347 2190 w 10 R f ( Class)1 270( +.)1 63( +)1 42(in C)1 173 4 1735 2190 t 10 CW f (complex)2311 2190 w 10 R f ( using)1 244(above was defined)2 748 2 2759 2190 t 10 CW f (friend)3778 2190 w 10 R f ( is some-)2 365(functions. It)1 510 2 4165 2190 t (times important that a function may be specified as a)9 2156 1 720 2310 t 10 CW f (friend)2906 2310 w 10 R f (in more than one class. Having the full list)8 1744 1 3296 2310 t ( the behavior of a)4 714(of members and friends available is a great advantage when you are trying to understand)14 3606 2 720 2430 t (type and especially when you want to modify it.)8 1923 1 720 2550 t ( and with the)3 570(Encapsulation issues increase dramatically in importance with the size of the program)11 3606 2 864 2670 t ( Snyder)1 316( See)1 202( dispersion of its users.)4 951(number and geographical)2 1032 4 720 2790 t 7 R f (18)3221 2740 w 10 R f (and Stroustrup)1 594 1 3324 2790 t 7 R f (19)3918 2740 w 10 R f (for more detailed discus-)3 1019 1 4021 2790 t (sions of language support for encapsulation.)5 1764 1 720 2910 t 10 B f (Implementation Issues)1 964 1 720 3150 t 10 R f ( run-time system and)3 859(The support needed for object-oriented programming is primarily provided by the)10 3317 2 864 3330 t ( builds on the lan-)4 722( of the reason is that object-oriented programming)7 2012( Part)1 212(by the programming environment.)3 1374 4 720 3450 t ( already pushed to their limit to support for data abstraction so that relatively few addi-)15 3485(guage improvements)1 835 2 720 3570 t (tions are needed\262.)2 723 1 720 3690 t ( language and its)3 692(The use of object-oriented programming blurs the distinction between a programming)10 3484 2 864 3810 t ( defined)1 329( more powerful special- and general-purpose user-defined types can be)9 2881( Since)1 278(environment further.)1 832 4 720 3930 t ( requires further development of both the run-time system, library)9 2710( This)1 237( pervades user programs.)3 1024(their use)1 349 4 720 4050 t ( these are integrated into a uni-)6 1260( Ideally)1 331( performance measuring, monitoring tools, etc.)5 1895(facilities, debuggers,)1 834 4 720 4170 t ( is the best example of this.)6 1091( Smalltalk)1 434(fied programming environment.)2 1279 3 720 4290 t 10 B f ( to Perfection)2 570(5 Limits)1 403 2 720 4530 t 10 R f ( and)1 173(A major problem with a language defined to exploit the techniques of data hiding, data abstraction,)15 4003 2 864 4710 t (object-oriented programming is that to claim to be a general purpose programming language it must)14 3995 1 720 4830 t ( on traditional machines.)3 988([1] Run)1 311 2 864 4950 t ( with traditional operating systems.)4 1408([2] Coexist)1 450 2 864 5070 t ( with traditional programming languages in terms of run time efficiency.)10 2899([3] Compete)1 505 2 864 5190 t ( with every major application area.)5 1391([4] Cope)1 355 2 864 5310 t ( must be available for effective numerical work \(floating point arithmetic without)11 3275(This implies that facilities)3 1045 2 720 5430 t ( that facilities must be available for access to)8 1895(overheads that would make Fortran appear attractive\), and)7 2425 2 720 5550 t ( must also be possible to write calls that con-)9 1850( It)1 117( drivers to be written.)4 881(memory in a way that allows device)6 1472 4 720 5670 t ( addition, it)2 459( In)1 133( required for traditional operating system interfaces.)6 2076(form to the often rather strange standards)6 1652 4 720 5790 t ( possible to call functions written in other languages from a object-oriented programming lan-)13 3922(should be)1 398 2 720 5910 t ( language to be called from a program)7 1563(guage and for functions written in the object-oriented programming)8 2757 2 720 6030 t (written in another language.)3 1120 1 720 6150 t ( completely rely on mecha-)4 1100(Another implication is that an object-oriented programming language cannot)8 3076 2 864 6270 t ( implemented on a traditional architecture and still expect to be used as a)13 3026(nisms that cannot be efficiently)4 1294 2 720 6390 t ( very general implementation of method invocation can be a liability unless)11 3126( A)1 132(general purpose language.)2 1062 3 720 6510 t (there are alternative ways of requesting a service.)7 1971 1 720 6630 t ( object-)1 329( Most)1 283( bottleneck.)1 493(Similarly, garbage collection can become a performance and portability)8 3071 4 864 6750 t 8 S1 f (__________________)720 6850 w 8 R f ( the support for data abstraction is)6 1135( However,)1 361(\262 This assumes that an object-oriented language does indeed support data abstraction.)11 2824 3 720 6950 t ( their support of object-)4 754( languages that support data abstraction are typically deficient in)9 2067( Conversely,)1 425(often deficient in such languages.)4 1074 4 720 7050 t (oriented programming.)1 733 1 720 7150 t cleartomark showpage saveobj restore %%EndPage: 19 19 %%Page: 20 20 /saveobj save def mark 20 pagesetup 10 R f (- 20 -)2 216 1 2772 480 t ( task of the programmer and to)6 1267(oriented programming languages employ garbage collection to simplify the)8 3053 2 720 840 t ( possible to use garbage)4 986( it ought to be)4 592( However,)1 449(reduce the complexity of the language and its compiler.)8 2293 4 720 960 t ( an alter-)2 362( As)1 165( matters.)1 348(collection in non-critical areas while retaining control of storage use in areas where it)13 3445 4 720 1080 t ( have a language without garbage collection and then provide sufficient expressive)11 3400(native, it is feasible to)4 920 2 720 1200 t ( is an example of this.)5 877( +)1 38( +)1 42( C)1 117(power to enable the design of types that maintain their own storage.)11 2707 5 720 1320 t ( that is best)3 462( feature)1 303( Any)1 224(Exception handling and concurrency features are other potential problem areas.)9 3187 4 864 1440 t (implemented with help from a linker can become a portability problem.)10 2860 1 720 1560 t ( major application areas using)4 1218(The alternative to having ``low level'' features in a language is to handle)12 2958 2 864 1680 t (separate ``low level'' languages.)3 1301 1 720 1800 t 10 B f (6 Conclusions)1 643 1 720 2040 t 10 R f ( abstraction is programming)3 1199( Data)1 263( programming using inheritance.)3 1379(Object-oriented programming is)2 1335 4 864 2220 t ( few exceptions, object-oriented programming can and ought to be a super-)11 3054( With)1 255(using user-defined types.)2 1011 3 720 2340 t ( primarily)1 408( abstraction)1 473( Data)1 248( techniques need proper support to be effective.)7 1965( These)1 298(set of data abstraction.)3 928 6 720 2460 t ( and object-oriented programming needs further support from)7 2459(needs support in the form of language features)7 1861 2 720 2580 t ( general purpose, a language supporting data abstraction or object-)9 2808( be)1 135( To)1 177(a programming environment.)2 1200 4 720 2700 t (oriented programming must enable effective use of traditional hardware.)8 2896 1 720 2820 t 10 B f (7 Acknowledgements)1 952 1 720 3060 t 10 R f ( Stock-)1 299(An earlier version of this paper was presented to the Association of Simula Users meeting in)15 3877 2 864 3240 t ( Kernighan and)2 625( Brian)1 277( contents.)1 388( discussions there caused many improvements both in style and)9 2588(holm. The)1 442 5 720 3360 t ( +.)1 63( +)1 42( thanks to all who helped shape C)7 1346( Also)1 239(Ravi Sethi made many constructive comments.)5 1882 5 720 3480 t 10 B f (8 References)1 589 1 720 3720 t 10 R f ( Graham et.al.:)2 617([1] Birtwistle,)1 670 2 864 3900 t 10 I f (SIMULA BEGIN)1 686 1 2188 3900 t 10 R f ( Chartwell-)1 490( 1971.)1 263( Lund, Sweden.)2 651(. Studentlitteratur,)1 762 4 2874 3900 t (Bratt Ltd, UK. 1980.)3 833 1 1114 4020 t ( Hoare, C.A.R.:)2 655( O-J. and)2 389([2] Dahl,)1 469 3 864 4260 t 10 I f (Hierarchical Program Structures)2 1366 1 2416 4260 t 10 R f (. In)1 172 1 3782 4260 t 10 I f (Structured Programming)1 1022 1 3993 4260 t 10 R f (.)5015 4260 w (Academic Press 1972.)2 890 1 1114 4380 t ( A.:)1 180( Tom)1 243([3] Cargill,)1 553 3 864 4620 t 10 I f (PI: A Case Study in Object-Oriented Programming)6 2233 1 1895 4620 t 10 R f ( Notices,)1 385(. SIGPLAN)1 527 2 4128 4620 t (November 1986, pp 350-360.)3 1179 1 1114 4740 t ( Study Group XI:)3 697([4] C.C.I.T.T)1 639 2 864 4980 t 10 I f (CHILL User's Manual)2 911 1 2225 4980 t 10 R f ( 1984.)1 250( March)1 310( Bulletin no 1. vol 4.)5 826(. CHILL)1 369 4 3136 4980 t ( M.A and Stroustrup, B.)4 964([5] Ellis,)1 459 2 864 5220 t 10 I f ( Reference Manual)2 759( +)1 50( +)1 54(The Annotated C)2 678 4 2337 5220 t 10 R f ( 1990.)1 250(. Addison-Wesley)1 746 2 3878 5220 t ( and Robson, D.:)3 720( A.)1 136([6] Goldberg,)1 652 3 864 5460 t 10 I f (Smalltalk-80: The Language and its Implementation)5 2166 1 2412 5460 t 10 R f (. Addison-)1 462 1 4578 5460 t (Wesley 1983.)1 549 1 1114 5580 t ( J.D. et.al.:)2 467([7] Ichbiah,)1 574 2 864 5820 t 10 I f (Rationale for the Design of the Ada Programming Language)8 2577 1 1948 5820 t 10 R f (. SIGPLAN)1 515 1 4525 5820 t (Notices, June 1979.)2 788 1 1114 5940 t ( B.W. and Ritchie, D.M.:)4 1056([8] Kernighan,)1 696 2 864 6180 t 10 I f ( Programming Language)2 1037(The C)1 254 2 2653 6180 t 10 R f ( 2nd)1 213( 1978.)1 263(. Prentice-Hall)1 620 3 3944 6180 t (Edition 1988.)1 545 1 1114 6300 t ( Sonya E.:)2 414([9] Keene,)1 529 2 864 6540 t 10 I f (Object-Oriented Programming in COMMON LISP)4 2037 1 1832 6540 t 10 R f (Addison-Wesley 1988.)1 921 1 3894 6540 t ( Ron:)1 223([10] Kerr,)1 457 2 864 6780 t 10 I f (Object-Based Programming: A Foundation for Reliable Software)6 2639 1 1572 6780 t 10 R f ( of the)2 263(. Proceedings)1 566 2 4211 6780 t ( of this)2 308( abbreviated version)2 841( An)1 188( 1986, pp 159-165.)3 806( August)1 355(14th SIMULA Users' Conference.)3 1428 6 1114 6900 t (paper can be found under the title)6 1377 1 1114 7020 t 10 I f (A Materialistic View of the Software ``Engineering'' Analogy)7 2517 1 2523 7020 t 10 R f (in SIGPLAN Notices, March 1987, pp 123-125.)6 1923 1 1114 7140 t cleartomark showpage saveobj restore %%EndPage: 20 20 %%Page: 21 21 /saveobj save def mark 21 pagesetup 10 R f (- 21 -)2 216 1 2772 480 t ( al.:)1 150( et.)1 147( Barbara)1 340([11] Liskov,)1 553 4 864 840 t 10 I f (Clu Reference Manual)2 904 1 2079 840 t 10 R f ( October 1979.)2 596(. MIT/LCS/TR-225,)1 834 2 2983 840 t ( al.:)1 157( et.)1 154( Barbara)1 347([12] Liskov,)1 553 4 864 1080 t 10 I f (Abstraction Mechanisms in Clu)3 1285 1 2107 1080 t 10 R f ( no 8, August 1977, pp)5 954( vol 20,)2 317(. CACM)1 377 3 3392 1080 t (564-576.)1114 1200 w ( Robert:)1 338([13] Milner,)1 547 2 864 1440 t 10 I f (A Proposal for Standard ML)4 1203 1 1787 1440 t 10 R f ( on Lisp and Functional Pro-)5 1217( Symposium)1 517(. ACM)1 316 3 2990 1440 t ( pp 184-197.)2 508(gramming. 1984,)1 711 2 1114 1560 t ( Kristen:)1 347([14] Nygaard,)1 618 2 864 1800 t 10 I f (Basic Concepts in Object Oriented Programming)5 1984 1 1855 1800 t 10 R f ( Notices, October)2 703(. SIGPLAN)1 498 2 3839 1800 t (1986, pp 128-132.)2 733 1 1114 1920 t ( Paul:)1 240([15] Rovner,)1 569 2 864 2160 t 10 I f (Extending Modula-2 to Build Large, Integrated Systems)6 2294 1 1707 2160 t 10 R f ( Vol. 3.)2 320( Software,)1 419(. IEEE)1 300 3 4001 2160 t ( 1986, pp 46-57.)3 658( November)1 471(No. 6.)1 247 3 1114 2280 t ( Jonathan:)1 417([16] Shopiro,)1 592 2 864 2520 t 10 I f ( Task System for Real-Time Applications)5 1675( +)1 50( +)1 54(Extending the C)2 662 4 1907 2520 t 10 R f ( USENIX)1 400(. Proc.)1 292 2 4348 2520 t ( Workshop, Santa Fe, November 1987.)5 1559( +)1 38(C +)1 109 3 1114 2640 t ( Standards Group, 1984:)3 1019([17] SIMULA)1 633 2 864 2880 t 10 I f (SIMULA Standard)1 762 1 2555 2880 t 10 R f ( Box)1 207( Post)1 238( Secretariat, Simula a.s.)3 988(. ASU)1 290 4 3317 2880 t (150 Refstad, 0513 Oslo 5, Norway.)5 1415 1 1114 3000 t ( Alan:)1 247([18] Snyder,)1 558 2 864 3240 t 10 I f (Encapsulation and Inheritance in Object-Oriented Programming Languages)6 3076 1 1694 3240 t 10 R f (. SIG-)1 270 1 4770 3240 t (PLAN Notices, November 1986, pp 38-45.)5 1720 1 1114 3360 t ( Bjarne:)1 345([19] Stroustrup,)1 692 2 864 3600 t 10 I f ( Programming Language)2 1065( +)1 50( +)1 54(The C)1 269 4 1953 3600 t 10 R f ( Edition)1 347( 2nd)1 227( 1986.)1 277(. Addison-Wesley,)1 798 4 3391 3600 t (1991.)1114 3720 w ( Bjarne:)1 327([20] Stroustrup,)1 692 2 864 3960 t 10 I f ( +)1 50( +)1 54(Multiple Inheritance for C)3 1085 3 1917 3960 t 10 R f ( of the Spring'87 EUUG Confer-)5 1362(. Proceedings)1 572 2 3106 3960 t ( May 1987.)2 458(ence. Helsinki,)1 621 2 1114 4080 t ( Bjarne:)1 322([21] Stroustrup,)1 692 2 864 4320 t 10 I f ( 1985-1989)1 461( +:)1 83( +)1 54(The Evolution of C)3 768 4 1906 4320 t 10 R f ( Computer Systems, Vol 2 No 3,)6 1324(. USENIX)1 444 2 3272 4320 t (Summer 1989.)1 589 1 1114 4440 t ( Bjarne:)1 340([22] Stroustrup,)1 692 2 864 4680 t 10 I f ( 1985-1987)1 479( +:)1 83( +)1 54(Possible Directions for C)3 1083 4 1942 4680 t 10 R f ( Workshop,)1 488( +)1 38( +)1 42( USENIX C)2 527(. Proc.)1 304 5 3641 4680 t (Santa Fe, November 1987.)3 1068 1 1114 4800 t ( D. and Moon, D.:)4 730([23] Weinreb,)1 618 2 864 5040 t 10 I f (Lisp Machine Manual)2 883 1 2237 5040 t 10 R f ( Inc. 1981.)2 427(. Symbolics,)1 523 2 3120 5040 t ( Niklaus:)1 364([24] Wirth,)1 508 2 864 5280 t 10 I f (Programming in Modula-2)2 1083 1 1761 5280 t 10 R f ( 1982.)1 250(. Springer-Verlag,)1 748 2 2844 5280 t ( P.M. and Bond, S.G.:)4 951([25] Woodward,)1 718 2 864 5520 t 10 I f (Algol 68-R Users Guide)3 1014 1 2575 5520 t 10 R f ( Majesty's Stationery Office,)3 1210(. Her)1 241 2 3589 5520 t (London. 1974.)1 586 1 1114 5640 t cleartomark showpage saveobj restore %%EndPage: 21 21 %%Trailer done %%Pages: 21 %%DocumentFonts: Courier Times-Bold Times-Italic Times-Roman Times-Roman