Object_Oriented_Programming_In_Python_2014_Goldwasser.pdf

(6231 KB) Pobierz
Object-Oriented Programming in Python,
© Copyright 2014 by Michael H. Goldwasser and David Letscher
Object-Oriented
Programming in Python
Michael H. Goldwasser
Saint Louis University
David Letscher
Saint Louis University
Object-Oriented Programming in Python,
© Copyright 2014 by Michael H. Goldwasser and David Letscher
© 2014 Michael H. Goldwasser and David Letscher
All rights reserved. No part of this book may be reproduced, in any form or by any means, without
permission in writing from the publisher.
This book was previously published by Pearson Education Inc.
Pearson Prentice Hall
TM
is a trademark of Pearson Education, Inc.
All other trademarks or product names are the property of their respective owners.
The authors of this book have used their best efforts in preparing this book. These efforts include
the development, research, and testing of the theories and programs to determine their effective-
ness. The author and publisher make no warranty of any kind, expressed or implied, with regard to
these programs or the documentation contained in this book. The author and publisher shall not be
liable in any event for incidental or consequential damages in connection with, or arising out of, the
furnishing, performance, or use of these programs.
Object-Oriented Programming in Python,
© Copyright 2014 by Michael H. Goldwasser and David Letscher
To Susan, who is both my wife and best friend,
and to our wonderful daughters Calista and Maya.
— Michael H. Goldwasser
To my wife Beth. Your love and support
makes everything possible.
— David Letscher
Object-Oriented Programming in Python,
© Copyright 2014 by Michael H. Goldwasser and David Letscher
Preface
We are excited to be sharing this book with you after years of developing material
for our own course at Saint Louis University. We have had a great time writing the book,
and we hope that our enthusiasm is contagious as you learn to program a computer.
Software development is both a skill and an art. At times is can be challenging,
yet when things work out it is very rewarding. As we guide you through the process,
please read the chapters carefully. However, we also encourage you to be an
active
learner.
Our lessons frequently contain examples of Python programs and a demonstration of the
behavior that might be observed when running those programs. Don’t take our word for it;
experiment on your own computer and see if you get the same results. Feel free to change
things, and see if those changes affect the outcome. While we do our best to organize the
discovery with our lessons, hands-on practice is a key component to success.
Why Object-Oriented Programming?
There are many different programming styles. Our book uses a particular paradigm known
as object-oriented programming. The characteristic of this style is the modeling of com-
ponents in a software system as
objects
that each have independent state information rep-
resented internally, as well as a set of supported behaviors that allow for interactions with
other components.
The primary advantage of object-oriented programming is that it provides a frame-
work for modeling a large complex software system as a collection of separate components.
This can aid in the initial design and implementation of software, in the subsequent main-
tenance of that software, and in the reuse of individual components in other contexts. For
these reasons, object-oriented programming has become the dominant style in industry for
large-scale software development.
Why Python?
Python is an object-oriented programming language developed by Guido van Rossum in
the early 1990s. It is an open-source language that is licensed and freely distributed by
the Python Software Foundation, a non-profit organization backed by several prominent
companies such as Google and Microsoft.
Python is designed with an extremely simple syntax, together with a powerful built-
in core. This combination facilitates the rapid development of software, making Python an
attractive choice for experienced software developers.
More recently, Python had emerged as a language for teaching computer science.
The very same properties that make Python popular for experienced programmers, such
as simplicity and robustness, make it attractive as an instructional language for beginners.
Our own switch to Python was based on the desire to spend far greater time teaching core
principles and far less effort distracted by artificial hurdles of a programming language. As
an object-oriented language, Python provides a simpler, more consistent model than other
traditional object-oriented languages such as Java and C++. While those other languages
remain prominent in industry, their complexity can easily overwhelm a beginning student.
(We provide a direct comparison between Python and Java or C++ in Appendix B).
iv
Object-Oriented Programming in Python,
© Copyright 2014 by Michael H. Goldwasser and David Letscher
Preface
v
Elements of the Book
We use a variety of elements when presenting material. The most notable are as follows.
A Word of Warning
Sometimes, we raise an issue in the flow of a lesson that is too important to be accidentally
overlooked. In such a case, we prominently echo the lesson in a separate displayed box,
such as the following:
Everyone should read such a warning, as it draws attention to a common pitfall.
For the Guru
Other times, we find ourselves in the middle of a discussion with a perfect opportunity to
present an advanced lesson, albeit one that is not immediately necessary. In these cases,
we present this extra lesson in a separate displayed box, such as the following:
This should be considered as optional reading, providing advanced lessons for the
motivated reader that are inspired by the surrounding discussion.
Case Studies
Sixteen designated case studies are incorporated into various chapters of the book. These
case studies can be treated as
optional
material, as we do not use them to introduce pri-
mary lessons. Instead, they allow us to reinforce techniques that were introduced in earlier
portions of a chapter. Furthermore, the case studies are often more comprehensive and
demonstrate the use of computers in a variety of real-world application areas (e.g., biol-
ogy, physics, mathematics, text analysis, graphics and animation, games and puzzles).
Chapter Reviews and Practice Problems
Each chapter ends in a consistent manner, with a summary of key points introduced in the
chapter, followed by a glossary of relevant terminology, and finally a collection of exercises
for the reader. Furthermore, some of the exercises are clearly labeled as
Practice.
For your
convenience, solutions to all practice problems are given in Appendix C.
Zgłoś jeśli naruszono regulamin