Answer the question
In order to leave comments, you need to log in
Examples of classes in programming?
Actually, can you give vivid examples of why classes are needed? What did not please many conventional, modular or procedural design? I mean, how is a variable in a class "better" than a global variable? And how is enum in C++ related to classes?
After all, you can do without classes ..
Answer the question
In order to leave comments, you need to log in
The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures."
Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.
On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object." At that moment, Anton became enlightened.
Classes are needed to implement an object-oriented approach in programming.
Therefore, it is more correct to compare OOP and Procedural or Modular Programming.
All approaches have their pros and cons, somewhere one approach is more convenient, somewhere else.
In short, the advantages of OOP:
* Encapsulation. Checking data access rights at the language level. You can't accidentally mess up someone else's variable. Combining data and data manipulation methods into one entity.
* Abstraction. You can work with objects as with a black box, without thinking about how it works inside.
* Inheritance. You can generate an entity based on an existing one by changing it a little. There is no need to fully describe the new entity, it is sufficient to describe only the differences.
* Polymorphism. You can work with a group of different entities through a common interface.
Yes, it is possible to implement all OOP patterns without using classes, objects and other things. But in fact, OOP allows you to do this more clearly and more conveniently in some cases. Those. you do not need to implement any patterns in your program, it's all done in the language itself for you. OOP is a kind of abstraction for working with data, as with objects in the real world.
It's just that there are areas where OOP is best suited for solving a problem. There are areas where it will not be optimal. The main thing is to know and understand where it is needed and where it is not. This already comes with experience.
Supporters of the "procedural approach" are strange, but I do not deny that everything can be done without OOP, but everyone forgot about the "readability of the code", in the "procedural approach" very often there is a wild shit code with which you can't figure out what and where it comes from (if the project is large), OOP is not needed for small projects, there will obviously be no reason for it (if this project does not need to be developed).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question