Chapter 6. Classes and object-oriented programming
This chapter covers
- An easier way to think about classes
- How to use classes to design your programs
Until now, we’ve been skimming over one of the fundamental ways you can organize your program in Python: the class. Classes and object-oriented programming are normally seen as big, scary things that real programmers use to write their programs, and you might think you need a lot of theoretical knowledge in order to use them properly. Nothing could be further from the truth. In Python, it’s possible to ease into classes and object-oriented programming.
In this chapter, you’ll start with the code you wrote back in chapter 2 to generate caves for Hunt the Wumpus and then see how much easier it is to write it using classes. Then you’ll build up from there into a full-fledged adventure game along the lines of Adventure or Zork. While you do that, you’ll find out all about Python’s classes and how to make the most of them.