文档介绍:T
E
A
M
F
L
Y
Team-Fly®
Foundations
of
Object-Oriented
Languages
This page intentionally left blank
Foundations
of
Object-Oriented
Languages
Types
and
Semantics
Kim B. Bruce
The MIT Press
Cambridge, Massachusetts
London, England
© 2002 Massachusetts Institute of Technology
All rights reserved. No part of this book may be reproduced in any form by any
electronic or mechanical means (including photocopying, recording, or information
storage and retrieval) without permission in writing from the publisher.
Library of Congress Cataloging-in-Publication Information
Bruce, Kim B.
Foundations of object-oriented languages: types and semantics /
Kim B. Bruce.
p. cm.
Includes bibliographical references and index.
ISBN 0-262-02523-X (hc. : alk. paper)
1. Object-oriented programming (computer science). 2. Programming lan-
guages (puters). I. Title.
.B776 2002
’17–dc21 2001054613
To my mother and the memory of my late father
Contents
List of Figures xi
Preface xv
ITypeProblemsin
Object-Oriented Languages 1
1 Introduction 3
Type systems in programming languages 4
Type checking and strongly typed languages 6
Focus on statically typed class-based languages 12
Foundations: A look ahead 13
2 Fundamental Concepts of Object-Oriented Languages 17
Objects, classes, and object types 17
Subclasses and inheritance 22
Subtypes 24
Covariant and contravariant changes in types 26
Overloading versus overriding methods 27
Summary 32
3 Type Problems in Object-Oriented Languages 33
Type checking object-oriented languages is difficult 33
Simple type systems are lacking in flexibility 35
Summary of typing problems 48
4 Adding Expressiveness to Object-Oriented Languages 49
viii Contents
GJ 49
Even more flexible typing with Eiffel 60
Summary 69
5 Understanding Subtypes 71