Using Ridiculous Starbucks Orders to Explain Python Classes

Ayla Yersel
Level Up Coding
Published in
6 min readMay 25, 2021

--

Photo by Naufal Giffari on Unsplash

Okay, you’re probably wondering — why Starbucks orders? Why not use normal things to explain classes? Alarm clocks? Cars? Bank accounts? Literally anything else?

Well, they say write about what you know — and I’m a millennial with a coffee addiction. So Starbucks it is, friends.

In this article, we’re going to create Python objects (*ahem* ridiculous Starbucks orders) using classes. We’ll explore classes in the context of object-oriented programming — but focus mostly on classes. (And coffee too, of course.)

Let’s go over some of the basics of object-oriented programming.

Okay, what’s object-oriented programming?

If you’re a new coder, odds are you’ve already worked mostly with procedural programming. Procedural programming works sort of like a recipe — with a series of tasks carried out in sequence using functions.

As its name suggests, object-oriented programming (OOP) carries out tasks using objects. A programming object is self-contained data type that has its own characteristics and actions. OOP allows coders to easily create and update data objects.

This is obviously a wildly over-simplified introduction to OOP. For a more complete introduction, check out Real Python, the w3schools website, or this awesome introduction to OOP by Tech With Tim on Youtube.

Cool. So what are classes?

Classes are object blueprints. They describe what characteristics an object has (its “attributes”) and what the object can do / have done to it (its “methods”). Classes allow users to create as many copies (or “instances”) of that object as we want. They’re especially useful for creating multiple objects of similar types — like, for instance, different Starbucks drinks.

Awesome. Now, let’s create the class we’ll use to make our objects.

Let’s create a “Drink” Class

Since I’m super creative, I’m going to go ahead and call this class “Drink”. We’ll use the following statement to create the “Drink” class:

class Drink:

--

--