I wonder if there was a way to add a parent class ...
# announcements
c
I wonder if there was a way to add a parent class to another class i cannot control via reflection, I have some generated code I cannot change
K 1
d
Reflection can't change the code, it can only introspect it.
c
👍
l
Why do you need to add a parent class? To have a function? A field? Just go with
extension functions
c
that's really complita to explain
but in my case i just solved the complexity by avoiding it
so i don't have to worry about it anymore
c
I’m curious. a) What did you want to achieve by giving a library class a new parent b) What did you do instead 🙂
c
i am using the openapi generator, generating code out of the API yaml and which calls the over HTTP
i generated 2 language clients, kotlin and java
these classes are generated as they are, and you can't change how they are generated without changeing the mustache templating or customizing the generator entirely
so you have 2 classes with same methods but they are not deriving from any other class
so adding an Interface at runing would have allowed me to use a strategy pattern and test them easily
because then I can implement 1 test method, and pass both the classes into into it if they implemented the same interface, problem is they don't, and I cannot add it at runtime... (this is what I wanted to do)
if you are curious I can show you the whole code and you see I have to test them separately with two test methods which look very similar yet i cannot use 1 and pass a different class, here it is:
Untitled.txt
PetApi both kotlin and java, implement the same API methods which I would need to call
for example in this case I call getPetById
that is some code which load tests the API which has to respond with 429 or some related message everytime it get's overloaded
so I bombard it with a bunch of requests
it's a kind of catch 22 situation, I wanted to simplify it so that I don't have to write twice the code all the time I want to test a call, no luck...
an alternative is to change the generator to add an interface on these 2 classes so that I can pass both with strategy pattern but it's way more complex to do that.
ah sorry
😁 1
👍 1
well I finished now
😄 1
🙂