The Good Old 'What Are Classes and Objects?' - in plain English

- written by someone who used to fake it till she made it.
Why Am I writing this –
(I am being kinda emotional here)
When I first started my CSE program, I was introduced to the concept of “classes and objects”, and I understood nothing…
I knew how to code. I loved coding. I knew that “if I write this, I’ll get that output.” I completed my entire Object-Oriented Programming course; by following instructions and writing code that worked. But deep down, I still didn’t understand what classes and objects really meant.
I felt like it would be better if someone explained these technical terms in my own language - the way I think, the way I speak.
Years later, I finally understand the concept a little better (not completely, but enough to help someone else). So I decided to write down what I know now.
Maybe someone out there will find this helpful, the version I wish I had when I had just started.
Now, enough with the sappy backstory. Let’s dive into the real stuff.
Classes & Objects:
Okay, so you’ve probably heard the phrase “a class is a blueprint for creating objects.” It’s the common definition. But let’s take a moment to unpack what it actually means.
The class acts like a design plan in code. We use these “design plans” to create “objects” which have the characteristics of real-life things. These characteristics, if one wishes to sound technical, are referred to as 'attributes'.
We can also perform some calculations or actions by defining “methods or member functions” on those objects –or using those objects as needed by our business logic.
Let’s try some analogies here. Suppose, you have a company of automobiles (yes, we are thinking big here). You manufacture cars like – sedans, SUVs, trucks, sports cars and so on. And you want to store the data (information) of your products (in this case, the cars) in the database. Since you know how to code (that’s why you are here. AND YES, you can have a car company and know how to code all at once. Your life, you rules), you will write a blueprint/design plan –or in programming terms a class, which will represent all your real-life products with their distinctive characteristics.
So you’ll write a class maybe called Car, it will have some characteristics (attributes) like–
Model_name
Color
Size
Engine_type
Car_type
Number_of_products
Now, let’s say, you want to perform an action. For example, whenever a new type of car is added (maybe you just launched a new design of your SUVs), the number of your products should increase.
Sure, you could update the number manually. But you are a developer, and developers think in terms of automation and smart solutions. So, inside the class, you will write a member function or a method which will increase the number of products automatically.
Like this, you will have more methods or member functions according to your needs.
At this point, you’ve just designed your plan.
Following this plan, when we instruct the CPU, it will create a virtual car (a Car type object), in the virtual world (inside your computer’s memory). This creating part happens with the help of the constructor . Another important concept of OOP.
One important thing to remember:
when you define a class — your blueprint — it’s just like writing down the plan on paper. No memory is allocated for it yet. Memory is only allocated when you actually create an object (also called an instance) of that class.
Now, I am not writing any code here. Our old best friend “google” or our new best friend “chatgpt” can help you with the code. But I am writing the pseudo code to give you a way to visualize how we usually design our plans aka define our classes.
Class Car:
Attributes:
model_name
color
size
engine_type
car_Type
number_of_products
Method:
add_new_product():
number_of_products += 1
This is a simple class that says, “Every car has a few qualities like model name, color, size, car type and engine type. And whenever a new car is added, the number of products increases by one.”
As for creating objects, we should know about “constructors”. But for now, let’s just know the syntax.
# We have defined our “Car” class before
# Now, we create a car object using the Car blueprint
my_car = new Car()
my_car.model_name = "Sedan X"
my_car.color = "Red"
my_car.engine_type = "Hybrid"
Here, my_car is the actual object – a (virtual) car created from the blueprint -Car. We’re giving it some specific values: the model name, color, and engine type.
In real code, the syntax will depend on the programming language, but the idea stays the same: You're creating a thing (object) based on a plan (class) and filling in its details.
Finally, a quick recap –
A class is the design plan used to represent a real-life thing in the virtual world.
An object is that real-life thing, created based on the class, inside your computer’s memory.
No memory is allocated when we define the class (we just write the plan).
Memory is only allocated when we actually create an object.
So here it is, my simple explanation for classes and objects in plain English. I tried to keep it short. Hope it will be helpful.
I am thinking of writing my next piece on “constructors” maybe. Who knows.
But till then, Adios!
Subscribe to my newsletter
Read articles from Quill Of A Coder directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
