2
I have the class
public class Conhecimento{}
This class extends from another class "Cteproc"
Only this Cteproc class has "versions" example.
V200.Cteproc
V300.Cteproc
My problem is that in creating the Knowledge class I need to tell if it will extend from Cteproc 200 or Cteproc 300 according to the version I receive. I was wondering if it is possible to do this, change the extends or leave Dynamic.
Create class at runtime?
– user28595
No, the classes already exist, I just want to inform of whom a class will extend at runtime.
– Mateus Veloso
There is no way, if the class is already written, as you will change after compiled, it is apparently impossible. I thought you wanted to write the class at runtime.
– user28595
I did not understand. Or if I understood, it is normal. If understanding is the opposite of what I am thinking, then it does not and would not make sense. If you clarify, maybe put an example, I try to comment better or answer. Is that what Articuno is saying? Maybe you can create a project pattern.
– Maniero
I will edit the question.
– Mateus Veloso
If you want to do this you’d better use it alone Generics, it doesn’t make much sense to use inheritance like that.
– Jéf Bueno
It would be better if you explained what problem you want to solve.
– ramaral
Yeah, it sounds like a scam, and there’s got to be another way to solve it.
– Maniero
@bigown if I didn’t get it wrong, it seems to me that he wants to alter the inheritance at "run time". Wouldn’t that be the same as "rewriting the class"? It seems to me a bit impossible, since in the execution, the class is already compiled.
– user28595
@Articuno seems architectural error, if there are two classes to be inherited, there must be two inherited classes, simple like this, but if the problem is another there may be a solution, it may be a case of composition, maybe using a Pattern specific.
– Maniero
This 'according to the version you receive'. You receive how? What defines that one or the other will be? And what is the difference between one and the other? The methods of both classes are the same but with different executions? It seems to me that you want to use inheritance and polymorphism. But it’s missing an understanding of how it works there can’t fit your problem.
– Wilker