A question for OOP experts. - page 17

 
Vladimir Simakov:
I mean the number of classes. Each one is 200 lines long.
How much harder would it be to access? I have a global kernel that's visible from everywhere. In OOP I would have to give it up. How would I work with elements in windows then? I get comatose when I try to imagine it.))
 
Реter Konow:
How much harder would access be? I have a global kernel that is visible from everywhere. In OOP I would have to give it up. How would I work with elements in windows then? I get comatose when I try to imagine it.))

Static class.

 

Vladimir Simakov:
А теперь к эффективности. Switch - это что в конечном итоге? Это последовательное сравнение параметра с константами. Внимание Петр, последовательное.

not necessary at all.

This does not mean that Peter is right or that the switch should be put everywhere, but nevertheless.

 
Alexey Navoykov:
Yes, that's right,so in terms of speed, it's obviously the fastest option in MQL. But the access tothe class objects in the managed environment is indirect.
Thank you for this brief overview. I take back what I said about switch.
 
Georgiy Merts:

That's right, more about this function. You have one monstrously sized switch that selects one of a dozen functions you need. In such a switch, it's very easy to make a mistake by accidentally writing code relating to one of the branches in the wrong place.

Things are much simpler with an overload. We have ten different descendants, and each time we work with ONE class, and it has ONE overloadable function. We cannot accidentally write it in another class, because we have to open a completely different file for it.

Plus - the parsing itself in this very huge switch is, in my opinion, much more stressful than opening the one class we need, and then parsing just one function.

In fact, in assembler code all this switch's handling anyway comes down to the same swich, depending on this pointer. But in case of OOP all this is hidden from the programmer and doesn't interfere with his work. Without OOP - you have to deal with it.

Roughly speaking, when you walk - you end up sending signals to your muscles in a certain sequence that move them. However, on the level of consciousness - you just remember which movement to make. Here, OOP is exactly that kind of "memory of what movement to make". You "don't understand why we need to remember the movement when we have a bunch of muscles, and nerves wired to them". well... I've said many times before, for titans of memorisation, it's really quite enough to remember which muscles have to be tensed in what sequence to go. There's no point in remembering the whole movement. For others, who cannot remember so much, it is much more reasonable to remember the whole movement, and what happens to the muscles, in what sequence they are tensed and to what extent - it is more reasonable to hide it from the mind.

Overloaded functions are just different functions to the compiler, and no switches.

 
Реter Konow:
How much harder would access be? I have a global kernel which is visible from everywhere. In OOP I would have to give it up. How would I work with elements in windows then? I get comatose when I try to imagine it.))

Why should that be?

The global kernel and OOP are not mutually exclusive.

Just elements in windows should be encapsulated inside window classes, not "Lying in plain sight". Just so no one can accidentally "get in the wrong place". Changing one variable and making a mistake about its location inside a huge global array is very easy, while it is much harder to query the right interface and then change the same variable in the right object and make a mistake.

 
Koldun Zloy:

Overloaded functions are simply different functions to the compiler, and no switch.

And how is the one that is needed selected ? We are talking about virtual functions and late binding. Which overloaded function will be called ? This is determined by the this pointer, which is passed implicitly when you call it. And how do you think this choice is made?

 
Georgiy Merts:

And how is the one we want selected? We're talking about virtual functions and late binding. Which overloaded function will be called ? This is determined by the this pointer, which is implicitly passed to the call. And how do you think this choice is made?

Actually, Peter was not talking about virtual functions.

But they don't have any switches either.

A class that has virtual functions has a virtual function table.

And every object of this class contains an implicit variable - a pointer to the virtual function table.

If one or all virtual functions are overridden in the descendant, a new table is created and the descendant instances contain a pointer to it.

 
Koldun Zloy:

Actually, Peter was not talking about virtual functions.

But they don't have any switches either.

A class that has virtual functions has a virtual function table.

And every object of this class contains an implicit variable - a pointer to the virtual function table.

If one or all virtual functions are overridden in the descendant, a new table is created and instances of the descendant contain a pointer to it.

Exactly. I'm asking, how does this same table work? In assembler code, it's the same switch.

And about "not talking about virtual functions" - it's kind of like "why OOP"... That is, it is about virtual functions, and not about simple identical names of functions with different arguments.

 
Georgiy Merts:

Exactly. So my question is: how does this very table work? In assembler code it's the same switch.

No. It's just an array of pointers to a function.

The assembly code takes a table address from the object.

It takes the address of the function at a certain position.

And a jump to that address is made.

What about "I wasn't talking about virtual functions" - that's what I meant by "why OOP"... That is, it's about virtual functions, not just the same name functions with different arguments.

Judging by his question, he was talking about functions with identical names.

He is most likely not even aware of virtual functions.

Reason: