Connecting OOP to Real-World Scenarios
In the introduction, we shared that Object Oriented Programming (OOP) is a paradigm for how we can organize code. Without seeing examples, that definition just feels… unhelpful. In this section, we won’t dig into code quite yet, but we’ll do some thinking and list making to set ourselves up to write code in the next section!
Let’s think about some components of the car factory that makes Fords. We may make some stuff up, but this analogy should help us build context for what OOP is.
- The factory has a machine that is designed to make a Ford Escape
- All Escapes have four wheels and four doors
- The color, interior fabric and engine size can vary from one Escape to another
With the information above, in theory, the manager at the factory should be able to say “please make a blue Escape with a leather interior and 2.5 cylinder engine”, and that should be possible.
That example about the car factory tie directly to concepts of OOP. We will use three main technical terms today. They are below, with the connection to the car factory example:
class- A class is like a blueprint or template. The factory machines are designed to make a car - that is the template for ALL Escapes. We could probably name it the EscapeCar class.
object/instance- An instance is an object that is made from the class template. The blue Escape that the manager requested (and was able to physically sit in and drive) is referred to as an object or instance of the EscapeCar class.
attribute- An attribute is a specific characteristic about an instance that has the potential of varying from other instances. With our Escapes, color, interior and engine would be attributes, because they weren’t programmed into the template, but were extra information the manager was able to give.
Classes and Objects - At Home!
Pick an object that you see sitting around in your home. It could be a candle, water bottle, glove, anything!
Jot down the following, and be ready to share out with the group:
- What type of object is it? i.e., what might the class name be?
- Are there multiple objects/instances of it in your home, or in the world? List a few.
- What are some of its attributes?
Are you still wondering how in the world this connects to writing software? That’s what we’ll discuss next!