Professional Documents
Culture Documents
Undergraduate Topics in Computer Science (UTiCS) delivers high-quality instructional content for
undergraduates studying in all areas of computing and information science. From core foundational
and theoretical material to nal-year topics and applications, UTiCS books take a fresh, concise, and
modern approach and are ideal for self-study or for a one- or two-semester course. The texts are
all authored by established experts in their elds, reviewed by an international advisory board, and
contain numerous examples and problems. Many include fully worked solutions.
Iain D. Craig
Object-Oriented
Programming
Languages:
Interpretation
Contents
1.
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Essential Properties of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Objects and Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Pure and Impure Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.5 Mixed-Paradigm Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.6 Organisation of this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1
3
6
7
9
9
2.
Class Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Slots and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Slot Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6 Visibility and Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.7 Instance Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8.2 Denition of Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.10 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.11 Part Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
13
16
20
22
23
25
31
34
34
35
40
44
49
3.
vi
58
64
65
65
67
72
73
73
73
78
4.
5.
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
5.2 Methods and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
5.3 Object Constructors and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 134
5.4 Environments and Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
5.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
5.4.2 Environments: A More Formal Denition . . . . . . . . . . . . . . 136
Contents
5.4.3
5.4.4
5.4.5
5.4.6
5.5 Static
vii
6.
7.
8.
C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
8.2 Classes and Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
8.2.1 Class and Instance Variables . . . . . . . . . . . . . . . . . . . . . . . . . 203
8.2.2 Access Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
8.2.3 Data and Method Access Modiers . . . . . . . . . . . . . . . . . . . 204
8.2.4 Instance Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
8.2.5 Static Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
8.2.6 Finalization and Destruction . . . . . . . . . . . . . . . . . . . . . . . . . 207
8.2.7 Dot Notation and Member Access . . . . . . . . . . . . . . . . . . . . 208
8.2.8 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
8.2.9 Indexers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
8.2.10 Self Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
8.3 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
8.3.1 Calling Base-Class Constructors . . . . . . . . . . . . . . . . . . . . . . 211
viii
BeCecil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
9.2 Programming Standard OO Mechanisms . . . . . . . . . . . . . . . . . . . . 232
9.3 Syntactic Sugar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
9.4 A Small Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
9.5 Concluding Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249