Up until recently I had been building up to Object Orientated Classes. I briefly discussed variables and functions, the building blocks of a class. While my take is a little simple I like to think of classes as custom data structures all their own. They allow you to associate any set of attributes that you like with one another in a very convenient manner. For example, a human class would have many variables to represent body parts, the skeleton, and so on. It would also have methods that allow it to move at different speeds or perform different tasks. You can do all of this outside of a class, but implementation can be clunkier or more difficult to communicate. There are other benefits too such as limiting availability to certain attributes, methods, or passing along attributes to other class objects.
Much like how the human body has skin to hide many organs, class objects can have limited scopes to perform a similar task. Limiting the scope of a method or variable can be important to ensure programmers do not accidentally touch things outside of the class they should not touch. For example, there may be a value that you want edited outside of the class under specific classes or never edited outside of the class. Requiring the use of getters and setters can limit access to variables to only necessary situations, and making them private with no way of changing can make them untouchable.
Lastly, C++ requires you to deallocate any memory dynamically allocated with the class with a destructor. However, Java and Python handle all of that for you automatically with garbage collection. At the end of the day keeping everything together neatly leads to cleaner code that can be easier to maintain. Refactorization can be a problem with classes, but it can be a problem with procedural programming too. I also feel that becomes a weaker argument as you become more familiar with Object Orientated programming.
If you make a purchase on Amazon using the link below I may receive a commission.
Tech Best Sellers