A class implements a public function that calculates some value. During the calculation the function creates temp data that I also want to retrieve.
I could either add a class member that stores that data which I can get after the function has finished, or give the function another parameter so that the callee has to take care of it. So it's basically
class A {
TempData member;
...
public Output function(Input input) {
// calculate return value and save temp data to member
}
}
vs.
class B {
...
public Output function(Input input, TempData fillme) {
// calculate return value and save temp data to fillme
}
}
My problem: both versions look wrong to me. The temp data doesn't really belong to class A and the function with the additional parameter in class B, I don't know...
Is there another solution? If not, which one of those two would you choose and why?
It sounds like you are struggling with a multi-output function problem. The best solution is to create a separate class that represents the return value of this function and holds your Output and TempData objects. Then you can cleanly return an instance of this class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With