Chapter 28. A More Realistic Example
We’ll dig into more class syntax details in the next chapter. Before we do, though, let’s take a short detour to explore a realistic example of classes in action that’s more practical than what we’ve seen so far. In this chapter, we’re going to build a set of classes that do something concrete—recording and processing information about people. As you’ll see, what we call instances and classes in Python programming can often serve the same roles as records and programs in more traditional terms. The main difference here is the customization that inheritance will enable.
Specifically, in this chapter we’re going to code two classes:
Person—a class that creates and processes information about peopleManager—a customization ofPersonthat modifies inherited behavior
Along the way, we’ll make instances of both classes and test out their functionality. When we’re done, this chapter will also show you a nice example use case for classes—we’ll store our instances in a simple object-oriented database, to make them permanent. That way, you can use this code as a template for fleshing out a full-blown personal database of your own written entirely in Python.
Besides actual utility, though, our aim here is also educational: this chapter provides a tutorial on object-oriented programming in Python. Often, people grasp the last chapter’s class syntax in the abstract but have trouble seeing how to get started when confronted with coding a new class from ...