Page 338 - Beginning Programming with Pyth - John Paul Mueller
P. 338

involved in classes that your head begins to spin around on its own. This chapter is about making class development simple and manageable. You can find the downloadable source code for the examples in this chapter in the BPPD_15_Creating_and_Using_Classes.ipynb file, as described in the book's Introduction.
Understanding the Class as a Packaging Method
A class is essentially a method for packaging code. The idea is to simplify code reuse, make applications more reliable, and reduce the potential for security breaches. Well-designed classes are black boxes that accept certain inputs and provide specific outputs based on those inputs. In short, a class shouldn’t create any surprises for anyone and should have known (quantifiable) behaviors. How the class accomplishes its work is unimportant, and hiding the details of its inner workings is essential to good coding practice.
Before you move onto actual class theory, you need to know a few terms that are specific to classes. The following list defines terms that you need to know in order to use the material that follows later in the chapter. These terms are specific to Python. (Other languages may use different terms for the same techniques or define terms that Python uses in different ways.)
Class: Defines a blueprint for creating an object. Think of a builder who wants to create a building of some type. The builder uses a blueprint to ensure that the building will meet the required specifications. Likewise, Python uses classes as a blueprint for creating new objects.
Class variable: Provides a storage location used by all
  




























































































   336   337   338   339   340