Questions on OOP in MQL5 - page 2

 
Yuriy Asaulenko:
Well, that's a bit too much. The man is all about OOP from the beginning. At least just by making a cup of coffee. Why are there any pattern breaks? IMHO, nonsense of inept teachers shifting their problems to students.
Read it carefully. That's what I'm saying: a person initially sets and solves his/her problems in a style approximating to OOP. But then he is taught procedural programming. After that the patterns are broken because it is procedural programming (not OOP) that differs greatly from human thinking.
 
Vasiliy Sokolov:

OOP should be explained without any code and all that abstruse nomenclature like classes, objects, pointers, etc. etc.

How does classical programming education work? At first, a student is agonizingly trying to move from human thinking to programming basics (loops, functions, variables and other stuff like that needed "knowledge baggage"). Then, when mess of functions, variables and if's forms some more or less orderly structure, the student is told: "Look: there is such a thing as OOP. Forget what you were taught before, and start thinking like a human again". What follows is a rupture of templates, the "baggage of knowledge" just obtained with such difficulty is thrown on the trash heap, and the person finds himself somewhere between heaven and earth. Naturally, this "PLO" is then remembered for several years as a bad dream with shuddering and pain in the remaining parts of the brain (the others have been scorched by the new knowledge).

No, I categorically state that one should not learn programming. On the contrary, it is harmful and dangerous. Instead it is necessary to teach thinking. And with that there is a complete failure of the classical method of learning.

Would you write an article
 
pako:
Write an article.
Don't
 
pako:
Write an article

Maybe. But Alexei might be even better able to explain the PLO.

 
Комбинатор:
Don't.
Are you writing already?
 
no )
 
Комбинатор:
no )
And don't write :)
 
Vasiliy Sokolov:
Read carefully. That's what I'm saying: a person initially sets and solves his tasks in a style approximating to OOP. But then he is taught procedural programming. After that a pattern break occurs because it is procedural programming (not OOP) which differs greatly from human thinking.

I don't see anything wrong with learning procedural programming beforehand. In order to learn how to write novels, it's a good idea to start by learning the regular alphabet and syntax and just learn how to read and write.

Actually, even by programming in just C/Pascal etc, we are already manipulating objects without knowing about their internal structure and functioning. It remains to explain that it is an object, and then to teach how to build these objects.

 
Alexey Volchanskiy:

....

Question:

Suggest a topic on OOP in MQL5 for 10 minutes, I will put it on youtube, i.e. it will be useful for everyone

------------------

Write everything that is interesting, I will sort it out, I will try to satisfy your requests within my free time

Good luck ))

Light up your work with objects.
 

Help me solve a problem. There are two buttons and a line. One button, when pressed, puts the line in edit mode, and when released, deletes the line. The second button, when clicked, fixes the line, and when clicked, puts it back in edit mode. Each button can change the colour and some other properties of the Line object. The "Line" object is defined globally. Is it possible to pass a reference to the "Line" object to each button immediately after creating buttons so that when you manipulate the reference variable inside the "Button" objects, all changes are remembered in the global "Line" object.

I've sketched out a simplified script below, instead of pressing a button, it's an addition() function that increments the counter of the "Line" object. I understand that you can pass the "Line" object as a function argument by reference, but just in the working version, there are several such functions, so I'd like to pass the reference at the very beginning once. I.e. is it possible to make Btn1.addition() or Btn2.addition() increase the gLine.count ?

class CLine
{
    public:
          int   count;
                CLine(void){count=0;};
               ~CLine(void){};
};


class CMyButton
{
    private:   
    public:
                CLine m_Line;
                CMyButton(void){};
               ~CMyButton(void){};
              
                void bind(CLine &aLine) {m_Line = aLine;}
                void addition() {++m_Line.count;}
};




CMyButton  Btn1;
CMyButton  Btn2;

CLine gLine;

void OnStart()
{
   Btn1.bind(gLine);
   Btn2.bind(gLine);
   
   Print("Line.count=", gLine.count);
   Btn1.addition();
   Print("Line.count=", gLine.count, "  Btn1.m_Line.count=", Btn1.m_Line.count);
   Btn2.addition();
   Print("Line.count=", gLine.count, "  Btn2.m_Line.count=", Btn2.m_Line.count);
   Btn1.addition();
   Print("Line.count=", gLine.count, "  Btn1.m_Line.count=", Btn1.m_Line.count);
   Btn2.addition();
   Print("Line.count=", gLine.count, "  Btn2.m_Line.count=", Btn2.m_Line.count);
}

This is what I have going on right now:


Reason: