Python - Classes

In this module, we will learn how to extend the functionality of Python through custom Classes, which allow you to represent an 'object' of any kind through the combination of local variables which store information about a particular instance of the object, as well as a set of functions that define what the object can do.

Introduction

While Functions make our code more efficient and reuseble, they still assume that the code is meant to be executed a single time. This is typical in design applications, where code is used to create relatively short 'scripts' that are meant to be run when needed to accomplish a specific task. This type of programming is commonly referred to as procedural programming, since each passage of code defines a single procedure that is meant to be executed once and runs top to bottom until it is complete.

For more complex modern programs, however, the program does not have a single specific behavior, but runs continuously and changes based on a user's input. Instead of just using Conditionals, Loops, and Functions to control the execution of the code, such programs rely on objects that define the different functionalities of the program. As the program runs, these objects can interact with each other and change their behavior based on user input and other events that are happening within the program.

This type of programming is called object-oriented programming or OOP, and is one of the major foundations of modern programming. The key to OOP are Classes, which defines the behavior of these objects. Although we will not get too deep into OOP within this sequence, creating custom Classes can be very useful for defining custom objects with specific behaviors even if we are using a mostly procedural approach. In a later module we will see how we can use Classes and OOP to create interesting design models based on agent-based behavior.