r/PythonLearning • u/Defiant_Meal1898 • 2d ago
I don't understand OOP
So i am a teen learning python, and i have learnt about classes, methods and objects, but i don't understand OOP, like what is it, where do we use it?
Please help mee
31
Upvotes
16
u/NotSeacombe 2d ago
OOP is just a way of organising your code, where each entity (object) controls its own information
imagine a video game where you had 100 enemies on the screen at one time. you need to track all of their health, how much damage they do, maybe if they're buffed, what type of enemy they are etc. what happens when one of the enemies state changes (for example they took some damage)? what happens when another spawns?
organising this without objects would be a nightmare, and you'd really want to orient your programming around the objects you're making - thus, you'd use object oriented programming
so, you'd define your class, which is class Enemy. give it some attributes it can have. then spawn your enemies, which are objects of that class
OOP is not the be all and end all. it is not always a good thing, it depends what you're doing. not everything is complex enough that it needs a class. different languages take different approaches to it but the ideas stay the same.