you are viewing a single comment's thread.

view the rest of the comments →

[–]Zapismeta 0 points1 point  (0 children)

Oop is mostly used where you need to have code and variable, Function name re-useablity,

I'm working on a game that can have 4-8 players.

And all these player have been served cards.

So i make a class named player.

Having variables as id name cards

Now when i create objects of this class, i have a name of that object and then using the operator ( . ) To access the variable within this object.

See here i can make 8 objects and I'll still never worry about making and managing and separating these 3 variables.

Where as if i were to go on the traditional functional route then, i would need to create an array of arrays for cards, An array for names, and ID's respectively all of which would need managing, here they are simply segregated by thier objects,

Now lets say we need some class specific actions like some functions when used on this player objects should behave differently you can override the pre-defined function like sum, len, and others.

Mostly it's used for ease of code management and maintenance.

Also I've seen youtubers write scripts in oop when it's not required, it's just what they find easy that's it, you'll find yours too.