ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
Third Edition
An Introduction to Object-Oriented Programming
Timothy A. Budd
Oregon State University
Boston San Francisco New York
London Toronto Sydney Tokyo Singapore Madrid
Mexico City Munich Paris Cape Town Hong Kong Montreal
Executive Editor: Susan Hartman Sullivan
Associate Editor: Elinor Actipis
Executive Marketing Manager: Michael Hirsch
Production Supervisor: Diane Freed
Composition: Windfall Software, using ZzTEX
Copyeditor: Debbie Prato
Technical Art: LM Graphics
Proofreader: Brooke Albright
Text Design: Windfall Software
Cover Designer: Gina Hagen Kolenda
Cover Illustration: Susan Cyr
Design Manager: Gina Hagen
Prepress and Manufacturing: Caroline Fell
Access the latest information about Addison-Wesley titles from our World Wide Web site: www.aw.xcom/cs
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed in initial caps or all caps.
The programs and applications presented in this book have been included for their instructional value. They have been tested with care, but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs or applications.
Library of Congress Cataloging-in-Publication Data
Budd, Timothy.
An introduction to object-oriented programming / Timothy A. Budd.3rd ed.
p. cm.
Includes index.
ISBN 0-201-76031-2(pbk.)
1. Object-oriented programming (Computer science) I. Title.
QA76.64B83 2002
005.1'17-dc21
2001045060
CIP
Copyright 2002 by by Pearson Education, Inc.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America.
..
Preface
When I began writing my first book on Smalltalk in 1983, I distinctly remember thinking that I must write quickly so as to not miss the crest of the object-oriented programming wave. Who would have thought that two decades later object-oriented programming would still be going strong? And what a long, strange trip it has been.
In the two decades that object-oriented programming has been studied, it has become the dominant programming paradigm. In the process, it has changed almost every facet of computer science. And yet I find that my goal for the third edition of this book has remained unchanged from the first. It is still my hope to impart to my students and, by extension, my readers an understanding of object-oriented programming based on general principles and not specific to any particular language.
Languages come and go in this field with dizzying rapidity. In the first edition I discussed Objective-C and Apples version of Object Pascal, both widely used at that time. Although both languages still exist, neither can at present be considered a dominant language. (However, I talk about Objective-C in the third edition because from a language point of view it has many interesting and unique features.) Between the first edition and the third many languages seem to have disappeared (such as Actor and Turing), while others have come into existence (such as Java, Eiffel, and Self). Many existing languages have acquired object extensions (such as Common Lisp and Object Perl), and many have burst onto the scene for a short while and then just as suddenly disappeared (for example, Sather and Dylan). Then there is Beta, a language that hints at wonderful ideas behind an incomprehensible syntax. Prediction is difficult, particularly about the future. Will languages that are just now appearing, such as Ruby, have staying power, or will they go the way of Dylan? What about C#? It is difficult to imagine that any language with Microsoft behind it will fail to be successful, but stranger things have happened. (Personally, I think that C# will last because it presents a route for Visual Basic programmers to finally progress to a better language, but that few Java or C++ programmers will migrate to the new language. Time will tell if my powers of foresight are any better than anybody elses.)
For the present edition I have expanded the number of languages that I use for examples, but I have eliminated many long narratives on a single language. Descriptions of techniques are often given in the form of tables or shorter explanations. As with the first two editions, I make no pretenses of being a reference manual for any language, and students producing anything more than trivial programs in any of the languages I discuss would do well to avail themselves of a language-specific source.
Nevertheless, in this third edition I have attempted to retain the overall structure I used in the first two editions. This can be described as a series of themes.
I. Introduction and Design. , are used in problem solving. The manipulation of physical index cards in a group setting is one of the best techniques I have encountered for developing and reinforcing the notions of behavior, responsibility, and encapsulation.
In the past decade the field of object-oriented design has expanded considerably. And for many readers may either be too little or too muchtoo much if they already have extensive experience with object-oriented modeling languages and design, and too little if they have never heard of these topics. Nevertheless, I have tried to strike a balance. I have continued to discuss responsibility-driven design, although it is now only one of many alternative object-oriented design techniques, because I think it is the simplest approach for beginning students to understand.