A question for OOP experts.

 

How do you do an OOP loop on objects and their properties?

For example, I execute a loop as follows

//Цикл по объектам в поиске нужного значения конкретного свойства.

for(int a1 = 0; a1 < obj_total; a1++)
  {
   if(G_CORE[a1][_X_SIZE] == THIS_SIZE)
     {
      G_CORE[a1][_this_state_color] = clrWhite;
      Redraw(a1);
     } 
  }

//Цикл по свойствам в поиске неверного значения

for(int a1 = 0; a1 < prop_total; a1++)
  {
   if(G_CORE[ELEMENT][a1] > Max_value)
     {
      G_CORE[ELEMENT][a1] = Max_value;
      Redraw(ELEMENT);
     } 
  }
 

Another interesting thing is how to create a hierarchy of objects or groups. For example, there are several categories, each category contains a group with n number of objects. What methods of building hierarchies does the OOP concept suggest?

An implementation of a hierarchy should provide easy transitions between its parts and levels in the loop. If we build a hierarchy inside an array, we will be left with a lot of empty space. If it is built from a complex of arrays it won't allow to freely loop through the links. What does OOP suggest?

 
Реter Konow:

How do you do an OOP loop on objects and their properties?

For example, I execute a loop as follows

CObj obj[];
...
for (int i=0;i<ArraySize(obj);obj[i++].CheckSomething(param));
It goes something like this. And inside the class, in the CheckSomething() method, all the logic is implemented.
 
Vladimir Simakov:
It goes something like this. And inside the class, in the CheckSomething() method, all the logic is implemented.

Thank you. First we assemble array obj[] from objects and then do a loop?

And what about the hierarchy? And we are talking about static hierarchy. Constant and unchangeable.

 
Реter Konow:

Thank you. First we assemble array obj[] from objects and then do a loop?

And what about the hierarchy? We are talking about a static hierarchy. Constant and unchangeable.

class Class1{
...
};

class Class2{
...
};

class Class3{
   Class1 class1;
   Class2 class2;
...
};
 
Vladimir Simakov:
So we create a hierarchy of classes and then collect all their objects in a separate class and loop through them?
 
Реter Konow:
So we create a hierarchy of classes and then collect all their objects in a separate class and loop through them?

It depends on what you need, but in principle this way. You agree that it's much more elegant than your arrays. And given my strong suspicion that theirmultidimensional arrays aren't actually arrays at all, since they cannot be passed into a dll, the overhead of function calls may well be the same.

 
Реter Konow:

How do you loop over objects and their properties in OOP?

The tag is Konow:
and through them do a loop through all links?

Use common terminology, not only can you mislead the other person with your question, but you will be sure that your question is answered

OOP Wiki - terms here.

for your information, you can make arrays of object instances (see above) or look at the sources WndContainer.mqh and ArrayObj.mqh , they are used to create graphical panels based on CPanelDialog (ready-made example in the folder ndicators\Examples\Panels\SimplePanel ), but they work with pointers and lists

 
Vladimir Simakov:

It depends on what you're after, but in principle that's how it is. You agree that it's much more elegant than your arrays. And given my strong suspicion that their multidimensional arrays aren't actually arrays at all, since they cannot be passed into a dll, the overhead of function calls may well be the same.

Well, perhaps more elegantly, I won't argue. I am very concerned with practicality, expediency, simplicity and convenience, and I look at any syntax as "the enemy of the people", because it requires attention, parsing, generates errors and hinders perception. That's why I try to use as simple and even primitive code constructs as possible. The main thing is that they should be easy to read and effective.

Of course, there's a snag in the hierarchy. If we did do it in an array, loops would provide more opportunities to parse links, groups, subgroups, sub-subgroups, etc... But the memory will be used inefficiently. If we use classes, it seems to be an ideal solution. But it's for a "dead" hierarchy. For an image. But if we need to create an engine that works with it - I'm afraid that here all this syntactic hell will break loose)).

 
Реter Konow:

Thank you. First we assemble array obj[] from objects and then do a loop?

And what about the hierarchy? We are talking about a static hierarchy. Constant and unchangeable.

Explain what you mean by "...It's a static hierarchy. Constant and unchanging"?
 
Igor Makanu:

Use common terminology, you may not only confuse the other person with your question, but you will be confident that your question has been answered.

OOP Wiki - terms here.

for a given subject, you can make arrays of object instances (see the answers above) or look at the sources WndContainer.mqh and ArrayObj.mqh , they are used to create panels based on CPanelDialog (you can find a ready example in the folder ndicators\Examples\Panels\SimplePanel ), but they work with pointers and lists

In OOP "object" means a reference to a class in which its fields (properties) are declared. By "object" I mean a numbered set of properties, each of which is a cell in an array. That's the difference.

The questions are not related to the topic of graphical interfaces. I have long since bypassed graphical libraries and have nothing to look for there. But, now I'm interested in AI, which raises new challenges and questions.

Reason: