
- •New to the Tenth Edition
- •Preface
- •Acknowledgments
- •About the Author
- •Contents
- •1.1 Reasons for Studying Concepts of Programming Languages
- •1.2 Programming Domains
- •1.3 Language Evaluation Criteria
- •1.4 Influences on Language Design
- •1.5 Language Categories
- •1.6 Language Design Trade-Offs
- •1.7 Implementation Methods
- •1.8 Programming Environments
- •Summary
- •Problem Set
- •2.1 Zuse’s Plankalkül
- •2.2 Pseudocodes
- •2.3 The IBM 704 and Fortran
- •2.4 Functional Programming: LISP
- •2.5 The First Step Toward Sophistication: ALGOL 60
- •2.6 Computerizing Business Records: COBOL
- •2.7 The Beginnings of Timesharing: BASIC
- •2.8 Everything for Everybody: PL/I
- •2.9 Two Early Dynamic Languages: APL and SNOBOL
- •2.10 The Beginnings of Data Abstraction: SIMULA 67
- •2.11 Orthogonal Design: ALGOL 68
- •2.12 Some Early Descendants of the ALGOLs
- •2.13 Programming Based on Logic: Prolog
- •2.14 History’s Largest Design Effort: Ada
- •2.15 Object-Oriented Programming: Smalltalk
- •2.16 Combining Imperative and Object-Oriented Features: C++
- •2.17 An Imperative-Based Object-Oriented Language: Java
- •2.18 Scripting Languages
- •2.19 The Flagship .NET Language: C#
- •2.20 Markup/Programming Hybrid Languages
- •Review Questions
- •Problem Set
- •Programming Exercises
- •3.1 Introduction
- •3.2 The General Problem of Describing Syntax
- •3.3 Formal Methods of Describing Syntax
- •3.4 Attribute Grammars
- •3.5 Describing the Meanings of Programs: Dynamic Semantics
- •Bibliographic Notes
- •Problem Set
- •4.1 Introduction
- •4.2 Lexical Analysis
- •4.3 The Parsing Problem
- •4.4 Recursive-Descent Parsing
- •4.5 Bottom-Up Parsing
- •Summary
- •Review Questions
- •Programming Exercises
- •5.1 Introduction
- •5.2 Names
- •5.3 Variables
- •5.4 The Concept of Binding
- •5.5 Scope
- •5.6 Scope and Lifetime
- •5.7 Referencing Environments
- •5.8 Named Constants
- •Review Questions
- •6.1 Introduction
- •6.2 Primitive Data Types
- •6.3 Character String Types
- •6.4 User-Defined Ordinal Types
- •6.5 Array Types
- •6.6 Associative Arrays
- •6.7 Record Types
- •6.8 Tuple Types
- •6.9 List Types
- •6.10 Union Types
- •6.11 Pointer and Reference Types
- •6.12 Type Checking
- •6.13 Strong Typing
- •6.14 Type Equivalence
- •6.15 Theory and Data Types
- •Bibliographic Notes
- •Programming Exercises
- •7.1 Introduction
- •7.2 Arithmetic Expressions
- •7.3 Overloaded Operators
- •7.4 Type Conversions
- •7.5 Relational and Boolean Expressions
- •7.6 Short-Circuit Evaluation
- •7.7 Assignment Statements
- •7.8 Mixed-Mode Assignment
- •Summary
- •Problem Set
- •Programming Exercises
- •8.1 Introduction
- •8.2 Selection Statements
- •8.3 Iterative Statements
- •8.4 Unconditional Branching
- •8.5 Guarded Commands
- •8.6 Conclusions
- •Programming Exercises
- •9.1 Introduction
- •9.2 Fundamentals of Subprograms
- •9.3 Design Issues for Subprograms
- •9.4 Local Referencing Environments
- •9.5 Parameter-Passing Methods
- •9.6 Parameters That Are Subprograms
- •9.7 Calling Subprograms Indirectly
- •9.8 Overloaded Subprograms
- •9.9 Generic Subprograms
- •9.10 Design Issues for Functions
- •9.11 User-Defined Overloaded Operators
- •9.12 Closures
- •9.13 Coroutines
- •Summary
- •Programming Exercises
- •10.1 The General Semantics of Calls and Returns
- •10.2 Implementing “Simple” Subprograms
- •10.3 Implementing Subprograms with Stack-Dynamic Local Variables
- •10.4 Nested Subprograms
- •10.5 Blocks
- •10.6 Implementing Dynamic Scoping
- •Problem Set
- •Programming Exercises
- •11.1 The Concept of Abstraction
- •11.2 Introduction to Data Abstraction
- •11.3 Design Issues for Abstract Data Types
- •11.4 Language Examples
- •11.5 Parameterized Abstract Data Types
- •11.6 Encapsulation Constructs
- •11.7 Naming Encapsulations
- •Summary
- •Review Questions
- •Programming Exercises
- •12.1 Introduction
- •12.2 Object-Oriented Programming
- •12.3 Design Issues for Object-Oriented Languages
- •12.4 Support for Object-Oriented Programming in Smalltalk
- •12.5 Support for Object-Oriented Programming in C++
- •12.6 Support for Object-Oriented Programming in Objective-C
- •12.7 Support for Object-Oriented Programming in Java
- •12.8 Support for Object-Oriented Programming in C#
- •12.9 Support for Object-Oriented Programming in Ada 95
- •12.10 Support for Object-Oriented Programming in Ruby
- •12.11 Implementation of Object-Oriented Constructs
- •Summary
- •Programming Exercises
- •13.1 Introduction
- •13.2 Introduction to Subprogram-Level Concurrency
- •13.3 Semaphores
- •13.4 Monitors
- •13.5 Message Passing
- •13.6 Ada Support for Concurrency
- •13.7 Java Threads
- •13.8 C# Threads
- •13.9 Concurrency in Functional Languages
- •13.10 Statement-Level Concurrency
- •Summary
- •Review Questions
- •Problem Set
- •14.1 Introduction to Exception Handling
- •14.2 Exception Handling in Ada
- •14.3 Exception Handling in C++
- •14.4 Exception Handling in Java
- •14.5 Introduction to Event Handling
- •14.6 Event Handling with Java
- •14.7 Event Handling in C#
- •Review Questions
- •Problem Set
- •15.1 Introduction
- •15.2 Mathematical Functions
- •15.3 Fundamentals of Functional Programming Languages
- •15.4 The First Functional Programming Language: LISP
- •15.5 An Introduction to Scheme
- •15.6 Common LISP
- •15.8 Haskell
- •15.10 Support for Functional Programming in Primarily Imperative Languages
- •15.11 A Comparison of Functional and Imperative Languages
- •Review Questions
- •Problem Set
- •16.1 Introduction
- •16.2 A Brief Introduction to Predicate Calculus
- •16.3 Predicate Calculus and Proving Theorems
- •16.4 An Overview of Logic Programming
- •16.5 The Origins of Prolog
- •16.6 The Basic Elements of Prolog
- •16.7 Deficiencies of Prolog
- •16.8 Applications of Logic Programming
- •Review Questions
- •Programming Exercises
- •Bibliography
- •Index

Summary 569
S U M M A R Y
Object-oriented programming is based on three fundamental concepts: abstract data types, inheritance, and dynamic binding. Object-oriented programming languages support the paradigm with classes, methods, objects, and message passing.
The discussion of object-oriented programming languages in this chapter revolves around seven design issues: exclusivity of objects, subclasses and subtypes, type checking and polymorphism, single and multiple inheritance, dynamic binding, explicit or implicit deallocation of objects, and nested classes.
Smalltalk is a pure object-oriented language—everything is an object and all computation is accomplished through message passing. In Smalltalk, all subclasses are subtypes. All type checking and binding of messages to methods is dynamic, and all inheritance is single. Smalltalk has no explicit deallocation operation.
C++ provides support for data abstraction, inheritance, and optional dynamic binding of messages to methods, along with all of the conventional features of C. This means that it has two distinct type systems. C++ provides multiple inheritance and explicit object deallocation. C++ includes a variety of access controls for the entities in classes, some of which prevent subclasses from being subtypes. Both constructor and destructor methods can be included in classes; both are implicitly called.
While Smalltalk’s dynamic type binding provides somewhat more programming flexibility than the hybrid language C++, it is far less efficient.
Objective-C supports both procedural and object-oriented programming. It is less complex and less widely used than C++. Only single inheritance is supported, although it has categories, which allow mixins of additional methods that can be added to a class. It also has protocols, which are similar to Java’s interfaces. A class can adopt any number of protocols. Constructors can have any name, but they must be explicitly called. Polymorphism is supported with the predefined type, id. A variable of id type can reference any object. When a method is called through an object referenced by a variable of type id, the binding is dynamic.
Unlike C++, Java is not a hybrid language; it is meant to support only object-oriented programming. Java has both primitive scalar types and classes. All objects are allocated from the heap and are accessed through reference variables. There is no explicit object deallocation operation—garbage collection is used. The only subprograms are methods, and they can be called only through objects or classes. Only single inheritance is directly supported, although a kind of multiple inheritance is possible using interfaces. All binding of messages to methods is dynamic, except in the case of methods that cannot be overridden. In addition to classes, Java includes packages as a second encapsulation construct.
Ada 95 provides support for object-oriented programming through tagged types, which can support inheritance. Dynamic binding is supported with classwide pointer types. Derived types are extensions to parent types, unless they are

570 |
Chapter 12 Support for Object-Oriented Programming |
defined in child library packages, in which case entities of the parent type can be eliminated in the derived type. Outside child library packages, all subclasses are subtypes.
C#, which is based on C++ and Java, supports object-oriented programming. Objects can be instantiated from either classes or structs. The struct objects are stack dynamic and do not support inheritance. Methods in a derived class can call the hidden methods of the parent class by including base on the method name. Methods that can be overridden must be marked virtual, and the overriding methods must be marked with override. All classes (and all primitives) are derived from Object.
Ruby is an object-oriented scripting language in which all data are objects. As with Smalltalk, all objects are heap allocated and all variables are typeless references to objects. All constructors are named initialize. All instance data are private, but getter and setter methods can be easily included. The collection of all instance variables for which access methods have been provided forms the public interface to the class. Such instance data are called attributes. Ruby classes are dynamic in the sense that they are executable and can be changed at any time. Ruby supports only single inheritance, and subclasses are not necessarily subtypes.
The instance variables of a class are stored in a CIR, the structure of which is static. Subclasses have their own CIRs, as well as the CIR of their parent class. Dynamic binding is supported with a virtual method table, which stores pointers to specific methods. Multiple inheritance greatly complicates the implementation of CIRs and virtual method tables.
R E V I E W Q U E S T I O N S
1.Describe the three characteristic features of object-oriented languages.
2.What is the difference between a class variable and an instance variable?
3.What is multiple inheritance?
4.What is a polymorphic variable?
5.What is an overriding method?
6.Describe a situation where dynamic binding is a great advantage over its absence.
7.What is a virtual method?
8.What is an abstract method? What is an abstract class?
9.Describe briefly the eight design issues used in this chapter for objectoriented languages.
10.What is a nesting class?
11.What is the message protocol of an object?
12.From where are Smalltalk objects allocated?

Review Questions |
571 |
13.Explain how Smalltalk messages are bound to methods. When does this take place?
14.What type checking is done in Smalltalk? When does it take place?
15.What kind of inheritance, single or multiple, does Smalltalk support?
16.What are the two most important effects that Smalltalk has had on computing?
17.In essence, all Smalltalk variables are of a single type. What is that type?
18.From where can C++ objects be allocated?
19.How are C++ heap-allocated objects deallocated?
20.Are all C++ subclasses subtypes? If so, explain. If not, why not?
21.Under what circumstances is a C++ method call statically bound to a method?
22.What drawback is there to allowing designers to specify which methods can be statically bound?
23.What are the differences between private and public derivations in C++?
24.What is a friend function in C++ ?
25.What is a pure virtual function in C++ ?
26.How are parameters sent to a superclass’s constructor in C++?
27.What is the single most important practical difference between Smalltalk and C++?
28.If an Objective-C method returns nothing, what return type is indicated in its header?
29.Does Objective-C support multiple inheritance?
30.Can an Objective-C class not specify a parent class in its header?
31.What is the root class in Objective-C?
32.In Objective-C, how can a method indicate that it cannot be overridden in descendant classes?
33.What is the purpose of an Objective-C category?
34.What is the purpose of an Objective-C protocol?
35.What is the primary use of the id type in Objective-C?
36.How is the type system of Java different from that of C++ ?
37.From where can Java objects be allocated?
38.What is boxing?
39.How are Java objects deallocated?
40.Are all Java subclasses subtypes?
41.How are superclass constructors called in Java?
42.Under what circumstances is a Java method call statically bound to a method?

572Chapter 12 Support for Object-Oriented Programming
43.In what way do overriding methods in C# syntactically differ from their counterparts in C++?
44.How can the parent version of an inherited method that is overridden in a subclass be called in that subclass in C#?
45.Are all Ada 95 subclasses subtypes?
46.How is a call to a subprogram in Ada 95 specified to be dynamically bound to a subprogram definition? When is this decision made?
47.How does Ruby implement primitive types, such as those for integer and floating-point data?
48.How are getter methods defined in a Ruby class?
49.What access controls does Ruby support for instance variables?
50.What access controls does Ruby support for methods?
51.Are all Ruby subclasses subtypes?
52.Does Ruby support multiple inheritance?
P R O B L E M S E T
1.What important part of support for object-oriented programming is missing in SIMULA 67?
2.In what ways can “compatible” be defined for the relationship between an overridden method and the overriding method?
3.Compare the dynamic binding of C++ and Java.
4.Compare the class entity access controls of C++ and Java.
5.Compare the class entity access controls of C++ and Ada 95.
6.Compare the multiple inheritance of C++ with that provided by interfaces in Java.
7.What is one programming situation where multiple inheritance has a significant advantage over interfaces?
8.Explain the two problems with abstract data types that are ameliorated by inheritance.
9.Describe the categories of changes that a subclass can make to its parent class.
10.Explain one disadvantage of inheritance.
11.Explain the advantages and disadvantages of having all values in a language be objects.
12.What exactly does it mean for a subclass to have an is-a relationship with its parent class?
13.Describe the issue of how closely the parameters of an overriding method must match those of the method it overrides.