A
A
Alexander Martynov2020-09-14 16:01:09
OOP
Alexander Martynov, 2020-09-14 16:01:09

How are objects handled in OOP?

I understand the beauty of OOP. But the stone of linear (functional, thanks for the correction) programming doesn't come off easily.
How many books I have already looked at C ++, but did not get an understanding if I create several objects by whom and how they are managed.
Let me explain the essence of the problem: there is a series of data from which, during sequential processing according to certain rules, a feature is selected to create an object, all the initial data of the object are extracted from the stream, then the object develops according to several possible scenarios and eventually dies. However, during the life of, say, the first object, several more can be formed and they develop according to the same rules and die, possibly earlier than the first.
So in linear programming, I have to create a list of "objects" and a loop for processing each "object". How is the situation in OOP, do I also need to program the list and work of objects, or is it enough to generate some kind of event, action, well, I DO NOT UNDERSTAND WHAT, so that the objects process a new portion of data?
Can someone on the fingers explain the simplicity of OOP or tell me a book not about the properties of OOP, but about how it works.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
H
HemulGM, 2020-09-14
@PODBOX

The main essence of OOP is in objects that can manage themselves and perform actions on themselves.

МояМашина.ПовернутьНалево, а не ПовернутьМашинуНалево(МояМашина).

Classes can be inherited. We can have a list of objects, for example a list of vehicles (for example, the list will consist of objects of bicycles, airplanes, cars). Objects themselves can have their own methods, for example,
МойВелосипед.ПодтянутьСпицы; МойСамолёт.Приземлиться;
which others don't, but may have common methods, such as the same rotation. And we can command the entire list to Rotate Left.
цикл для i от 0 до 100 делать СписокТранспорта[i].ПовернутьНалево.

In the list of transport, as I said, there are planes and helicopters, but they will all execute the command, because. all of them will be inherited from the Transport class, which has a Turn Left method.

A
Adamos, 2020-09-14
@Adamos

OOP is not some kind of fundamentally different programming, it's just a way to collect data and functions that process it in one place and remove it from all other places that this internal kitchen does not concern.
You have a rather confusing explanation, I understood it like this: you have an object - the stream parser reads the next portion of data and processes it (creating new objects or modifying existing ones), after which you need to update existing objects and give information about them to the "graph". Accordingly, the parser must have a method that reads the input; member - a vector of created objects that have a common traversal interface; and a vector traversal method called after each read.
The "chart" can be an object, a reference to which is passed to each object upon creation, or it can be drawn by the parser according to the information received when traversing the vector ... well, you know better.
As a result, the same ten functions of yours will simply be shoved where they are directly needed, and the data will be available to them, and not to all the code at once. This both disciplines and allows you to make more flexible, supported solutions. However, this does not manifest itself in the code of ten functions, of course.

D
Denis Zagaevsky, 2020-09-14
@zagayevskiy

They are not controlled by anyone. Specifically, in C++, you can think of objects as structures, with functions bound to them that have an implicit this argument.

M
Mercury13, 2020-09-14
@Mercury13

An object is a regular structure, and from the fields that are implicitly written into objects, there are one or more pointers to virtual method tables. (Multiple if there is multiple inheritance.)
In OOP, just like in procedural, do it; An additional question is what to do if there can be objects of different types in one list. For example, you can do . std::vector<std::unique_ptr<SomeBase>>

A
Alexander Martynov, 2020-09-14
@PODBOX

Good people, I just wrote to the first commentator, but I see that the comment is not being opened here.
I repeat, judging by your words:
I need to create an object factory that detects the situation of a burst egg and writes it to its list, and with a new portion of data, it not only looks to see if any other object has hatched, but also calls the data processing method of all objects in the list ... and why then OOP, wrote a structure with a state semaphore, a dynamic array and a dozen functions that work in accordance with the semaphore, only these are linear programming methods, each correction is a run through the entire code ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question