At this beginning of this course, we compared computer code to a recipe: A recipe has ingredients and instructions, and computer code has data (variables) and statements.
Functions let us organize and “hide” our instructions, letting us execute lots of instructions with a single statement. They make our code a bit easier to understand, easier to organize, and more powerful.
However - let’s think about the more complex computer programs we deal with on an everyday basis:
What do all these types of software have in common?
Well, they all have various Objects in them.
Object-Oriented Programming (or OOP for short) refers to a way of coding that builds on this concept of objects.
An Object in code will have two types of things on it:
As an example, let’s say we wanted to write a program that has a cat in it. First, let’s think about the attributes a cat might have that make it unique:
Given what you know about writing code, how would you express these attributes?
That’s right, with variables! It’s just that in this case, these variables conceptually all belong to a single object.
Next, let’s think about the things a cat does:
These are all verbs describing actions. What does that remind you of when it comes to code? That’s right - these actions could all be expressed as statements in code. It turns out that in Object-Oriented Programming, the statements for an object are always organized into methods, aka “member functions”.
If this is all a little confusing - no worries, we’re going to go ahead and build this Cat object in the next section, and all will become clear!