+ 2

Can you give me a practical example of why classes are so important? What is their big usefulness?

That would help me understamd those better

14th Apr 2017, 8:40 AM
infinity
infinity - avatar
3 Answers
14th Apr 2017, 9:41 AM
JΞΜΔ đŸ‡šđŸ‡©đŸ‘‘
JΞΜΔ  đŸ‡šđŸ‡©đŸ‘‘ - avatar
+ 4
well, imagine a huge program, like you are going to code a big game with a lot of characters, weapons, maps, and ... now, how are you supposed to code it? any idea better that classes? classes are used to make objects with specific features and behaviors, so, you can have a class for each of you weapons and players, as a result, when you want to create the gameplay, you have each of your players and weapons as an objects, that you dont need to know about their inside, you have coded them before, and each of them is now a whole, so you just instantiate one and use it. thats for coding it for the first time, now think of maintenance, you want to keep your code as clean and human-readable as possible sp that you can update it later, now, you are going to fix some bugs or add some features to some of weapons fr the next update for example, all you got to.do is to find the object and change what is necessary, nothing about your gameplau changes, nothing about anything else changes, and you did that change in a very short time and with no hard work! and at last, again think of your game, you may have some weapons, that are similar, but there are some differences, with the help of polymorphism, you can easily create a virtual object that covers their similarities, now you can use that object to define two other objects that have the same behaivior in those similarities, but are actual different objects.
14th Apr 2017, 8:54 AM
Mohammad Ganji
Mohammad Ganji - avatar
+ 4
its the basis of oop. class is a module of code you can call to carry out a specific function. like if you make a banking app you will need code to create a user. you won't code that same piece over in every stage of the app. anywhere the app allows you to create an account that piece of code will be used. you use that class for that.
14th Apr 2017, 8:54 AM
Andre van Rensburg
Andre van Rensburg - avatar