Classes

An object-oriented program consists of a bunch of objects that have attributes and behaviors. A class is a description of the attributes and behaviors of a type of object. For instance, the code for the PacMan class would include the move and chomp methods, which are descriptions of how a PacMan object moves and chomps, respectively. The class is just a description of what a PacMan would be like, but it does not create a PacMan (that is the job of the instance). One of the big advantages of using classes is how it organizes your code. When you have a PacMan class, you know that all the code that describes a PacMan must go into the PacMan class definition. If sometime in the future you decide that you want PacMan to be able to jump, you ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.