What is a class? Metaphor please


#1

Hi, I'm new to coding and thankful for codeacademy. What an awesome place!

I've recently ran into the concept of "class", would someone please use non-technical language to explain to me what a class is, and how its used? I'm finding it challenging to wrap my head around the concept.

Thanks

Daniel


#2

It's something that describes a value type, like a blueprint.

The string class describes what a string is, a string is an instance of the string class.

Go google for explanations or youtube videos, there are sure to be plenty and you get to pick and choose between explanations.


#3

Thanks for the effort, I have googled and youtube'd, most explanations are technical.


#4

A class is just a blueprint based on which actual objects are created. So, consider the blue print of a Dream car:

Now, it has wheels, headlights, doors, engines, brakes, and everything. But the thing is that you can't use them. You need to create an object based on the class to use it. Here's an object Ferrari based on the class:

Now, it has instance variables doors, wheels, and methods like accelerate, brake, etc. These can be used by you. You can also create multiple objects, like Lamborghini, Honda, etc. based off your original blueprint Dream. These objects share common properties like doors, wheels, etc. as well as methods like accelerate, brake, etc, but have different values for them. So, Ferrari might have 4 wheels but Lamborghini have 8 and so on.

Hope it helps! :smiley: Do reply for clarification if needed!


#5

High five, thanks that was a great metaphor gaurangtandon.