Execute a class function based on a property

0

Please, I need to execute a function of a class among several classes that only know which one is correct from the value of one of its properties.

I create classes for example:

 public tabelaSerie = new clsTabela('Serie');
 public tabelaAlunos = new clsTabela('Alunos');
 public tabelaNotas = new clsTabela('Notas');

So I instantiate a class by setting the property "tableName" to the name of the table in use in this class.

The class has the "locate (key)" function. Now I need to use the "locate" function on a class that has the "tableName" property equal to "Students".

And there's no way I can do it this way (hypothetical example):

clsTabela('Alunos').locate(chave);

That is, use the locate function on the class that has the tableName property equal to "Students" but I do not know which of these instantiated classes is.

I would have to go through the classes one by one by checking which one has this property set to this value "Students" and then executing the locate function of this class. Something like going through checking with a typeOf (but it would not be with typeOf)

And I'll also need to know how I find a list of objects for which to identify which are instantiated classes.

Hypothetical Example:

matricula = 543768776;
objetos = >>Objetosqueexistem<< // Não sei de onde obter esta relação de objetos
foreach (var obj in objetos) {
    if ( obj.hasOwnProperty('tableName') ) {
        if ( obj.valueOfProperty('tableName') == 'Alunos' ) {
           obj.locate(matricula);
        }      
    }

Of course in practice it is not easy to know which class, in my use this class may vary, may not be exactly "Students", I will need to do this execution within the base class, I mean, after it is instantiated it will have to execute locate in another class depending on which one it is. Many people always ask what use to be able to reason better in the response so I explain that it is unpredictable to even know which class I will execute the function, I will even have to locate it to then apply the function with parameters because this execution will occur only within the class, is not an execution in my code at the level of my business rules.

Thanks for the attention, hug!

    
asked by anonymous 10.02.2018 / 15:37

0 answers