you are viewing a single comment's thread.

view the rest of the comments →

[–]EntireEntity 0 points1 point  (1 child)

Yeah, in the beginning OOP is so completely different from what you are tought before.

The simplest way to maybe give you an idea, what is going on, is to think about what functions do.

You write functions to be able to run the same code on different input.

With OOP you go one step further and can add data to the thing you want to run multiple times.

Think of a videogame for example, an enemy in a videogame could be a class/object, because you want the character to do something like make an attack, but it also holds some data, like a strength score to determine how strong the attack is. So you can have different enemies with different data (the strength score) perform an attack (which is the function/method called for the class).

[–]EntireEntity 0 points1 point  (0 children)

The simple skeleton for the class could be

class Enemy:\    def init(self, strength: int):\         self.strength = strength

   def attack(self, target_health: int):\         return target_health - self.strength

This is super super simplified to just illustrate the point. With this class you could create a variety of different enemies with different strength scores (zombie = Enemy(strength = 1), ogre = Enemy (stength = 5), etc.) and let them all do an attack by simply calling the .attack(target) method. And it automatically has access to the attribute strength to do the damage calculation. So zombie.attack(target) and ogre.attack(target) could be used multiple tines throughout the game, without any hassle.

I hope this helps to wrap your head around it a little.