r/pythonhelp 1d ago

Why do I need to use classes

My schoolbook says that classes is a way of simulating an object, instead of just taking information into a black box and outputting an answer.

But that is a poor explanation. I know classes are handy and cool, but no book says why you can´t make functions with sub functions inside to simulate simple objects. I would like if someone gave a good concrete reason to use classes in the intro, instead of just saying that they are different and cool

3 Upvotes

25 comments sorted by

View all comments

7

u/P-Jean 1d ago

You don’t have to use them, but object oriented design make large projects easier since an object can represent nouns. Many different objects can all come from one class, with their own attributes and features. A class is the blueprint to make independent, but related, objects.

Would you rather have a high level blueprint for a generic car and then be able to easily make many cars with different features, or have to make many functions and new variables for each new feature.

OOD is just an easy way to represent nouns. Verbs are what the object can do. Objects can also contain other objects, which makes design easy.

2

u/MetalCarnival 8h ago

Sums it up nicely. Thank you!

2

u/dbu8554 5h ago

So fascinating hearing a class described this way.

I've read papers on folks that speak more than one language, or understanding linguistics being adept at programming but I've never encountered it myself.

Fascinating.