A question for OOP experts. - page 4

 
Igor Makanu:

access rights modifiers allow to detect errors at compile time

In general, all this does not complicate the work with classes, do not use it, write everything in public: and then it will be easier to work with them.

SZZY: A lot of nice phrases about OOP, encapsulation and inheritance... This is all good, but the most important advantage of OOP over other programming styles is storage of all data (class fields) and functions of work with these data (class methods) in one place (class) - in book it is encapsulation. Further use of OOP depends on tasks, if the task allows to scale classes, then hierarchy will be needed and there will be base classes and their descendants - whether to use it, depends on you

All object properties can also be "encapsulated" in an array. There you can also specify the relationships between objects via specific pointer properties. There is an order there, because each property is indexed and its value is stored in a specific cell. The objects themselves are encapsulated in kernel. Access is simplest - by object number and property number. Transitions between objects of the same control are via properties-pointers.
 
Реter Konow:
You can also "encapsulate" all of an object's properties in an array. You can also specify relations between objects via specific pointer properties. There is an order there, because each property is indexed and its value is stored in a specific cell. The objects themselves are encapsulated in kernel. Access is simplest - by object number and property number. Transitions between objects of the same control are via properties-pointers.

this is not convenient in the first place!

Moreover, you have already written above about code readability (as well as above you mentioned speed - execution speed, depends on something else, not on programming style)

in general, like everywhere else - you won't know until you try, start to write in OOP style, you will get specific actions and specific questions, an example is already in this thread

If we are talking about AI, you also need to separate the data from the work with them, with OOP it will be easier to do it

SZZ: What is better in OOP? For example, there is different type of data, let it be Expert Advisor settings in MQL, and these settings have repetitions in blocks. We take one block of settings and describe class fields to pass these settings into a class, it is easier to create a constructor with parameters, and then write methods that work with these EA settings. Having done all that, we create either an array of class instances, or even just a few instances of the class ("class type variables") and that's it - the problem is solved by writing one class, not creating several arrays, creating methods to identify each array, creating a group of functions that, besides making changes in arrays, are not enough to spoil data that should not be processed in this call....

ZZZY: imho, OOP is just convenient, there is a certain legend that there is no need to use OOP if there is no inheritance... no comment, it's going to be a foamy argument without me

 
Igor Makanu:

this is not convenient in the first place!

Moreover, you have already written above about code readability (as well as above you mentioned speed - execution speed, depends on something else, not on programming style)

in general, like everywhere else - you won't know until you try, start to write in OOP style, you will get specific actions and specific questions, an example is already in this thread

If we are talking about AI, you also need to separate the data from the work with them, with OOP it will be easier to do it

SZZ: What is better in OOP? For example, we have different types of data, let it be Expert Advisor settings in MQL, and these settings have repetitions in blocks. We take one block of settings and describe class fields to pass these settings into a class, it is easier to create a constructor with parameters, and then write methods that work with these EA settings. Having done all that, we create either an array of class instances, or even just a few instances of the class ("class type variables") and that's it - the problem is solved by writing one class, not creating several arrays, creating methods to identify each array, creating a group of functions that, besides making changes in arrays, are not enough to spoil data that should not be processed in this call....

ZZZY: imho, OOP is just convenient, there is a certain legend that there is no need to use OOP if there is no inheritance... no comment, it's going to be a foamy argument without me

Comfortable or not, subjective question. I prefer a tabular layout of the data. Others prefer it in the form of a bunch of grapes or a tree. Others prefer it as a bunch of grapes or a tree. But, I will seriously think over your words and try to learn the basic principles of working with data in OOP.
 
Реter Konow:
Comfortable or not, subjective question. I prefer a tabular layout of the data. Others prefer it in the form of a bunch of grapes or a tree. Others prefer it as a bunch of grapes or a tree. But, I will seriously think over your words and try to grasp the basic principles of working with data in OOP.
I've already told you once that an array of pointers to arrays of pointers is a two-dimensional table. One list is rows, the lists that lie in the first are columns. They can have their own lists. And so on until the sun goes down. This is the hierarchy you are looking for. And it is performed by just one class.
 
Реter Konow:

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

Peter, you need to clearly understand that when the class itself is defined, no memory is allocated, even if there are instances of other classes inside the class as its properties. Therefore, there can be no reference to the class, but only to the class object. Memory is allocated when an instance (object) of a class is declared (created).

HH i.e. if there is a class in the program, but no instances of it, the compiler will ignore (not notice) that class.

There is one exception. The memory can be allocated when the class is defined for static methods and parameters, if any.
 
Artyom Trishkin:
I once told you that an array of pointers to arrays of pointers is a two-dimensional table. One list is rows, the lists lying in the first are columns. They can have their own lists. And so on until the sun goes down. This is the hierarchy you are looking for. And it is performed by just one class.

In theory, yes. But it is necessary to organise in such a way that transitions between hierarchical links (conditionally - induction and deduction, i.e. from particular to general and back) are performed as a chain. That is, the order of pointers should be structured in a special way to allow moving in any (right) direction, without excessive "turns" and "jumps" in the loop. Therefore, a simple table layout of the pointers will probably not work.

Added:

But it might work. I don't know yet.

 
Igor Makanu:

We need to put these questions into practice, otherwise we won't be able to see what is convenient and what seems inconvenient )))).

Here is a trivial example, which is used in MQL a hundred and fifty times - determination of a new bar:

OK, this is a working code, but what if I need to define a new bar for 2 TFs? And what if I want to use all the TFs from the terminal?

it would be like this in OOP:

and all I have to do now is to declare several instances ofCNewbar class- how? even to an array, even to several variables, but I have protected data from accidental change with OOP

I have already solved this problem publicly. The idea was to create a table of all symbols and all timeframes and loop through it, fixing the events of a new bar. After the first call of any function of this event, its flag is erased from the table. I can not judge how much more complicated it is than in OOP. But, in fact, rather simple and convenient solution.

 
Nikolai Semko:
Peter, you have to clearly understand that the class itself is not allocated memory, even if there are instances of other classes inside the class as its properties. Therefore, there can be no reference to the class, but only to the class object. Memory is allocated when an instance (object) of a class is declared (created).
HH i.e. if there is a class in the program, but no instances of it, the compiler will ignore (not notice) this class.
I did not know about that. Interesting. The problem is the extent to which using OOP will allow easy handling of all hierarchy data in loops. It is the loops that are the main mechanisms of any engine. The better the loops work - the more data you can dig through and the more work you can do.
 
When a class object is created, apart from allocating memory for all properties (variables) of the class, one of the constructors is started (there may be more than one). The constructors can be non-parametric (default), parametric (when some parameters are specified when creating an instance of a class, or a copy constructor, when another instance of the class is specified as a parameter of an instance of the class.
 
Реter Konow:
In theory, yes. But it is necessary to organise in such a way that transitions between hierarchical links (conditionally - induction and deduction, i.e. from particular to general and back) are performed as a chain. That is, the order of pointers should be structured in a special way to allow moving in any (right) direction, without excessive "turns" and "jumps" in the loop. Therefore, a simple table layout of pointers probably won't work.
All lists are already endowed with a binary search. This means filtering by the searched property, rather than going through it one by one. As a result we get the index of the item we are looking for.
Reason: