0
What are the advantages of using classes and OOP?
Maybe my question is stupid but I don't feel that OOP and classes are easy and reliable to use. I understand (or maybe not??) the logic of classes but I think it makes more issues than benefits. If you want to use class that you weren't create you must study what kind of methods it have and decide whether it is useful or not. And when I create class with huge amount of methods I will have to create a documentation to it, because I will forget what's in it. So my questions is: What are the advantages of using classes and OOP? Thank you in advance for answers.
1 Réponse
+ 2
Do you really think that bundling stuff in a class is more work than writing the same stuff without using a class? It's more or less the same, but implementing a class is better from an organizational point of view.
The four major principles of OOP are encapsulation, abstraction, inheritance and polymorphism.
Encapsulation: hiding the data implementation by restricting access to accessors and mutators. This allows you to be able to change the implementation at any time without worrying about the code that uses your class.
Abstraction: implementation of an object that contains the same essential properties and actions we can find in the original object we are representing. (Meaning, we reduce what we are representing to what we have an interest in.)
Inheritance: a class can inherits attributes and/or methods from another class. A way to reuse code of existing objects, or to establish a subtype from an existing object, or both.
Polymorphism: one name, many forms. You can have multiple methods with the same name, but slightly different functionality. See overriding and overloading.