A way to return multiple return values from a method: put method inside class representing return value. Is it a good design?
- by john smith optional
I need to return 2 values from a method. My approach is as follows:
create an inner class with 2 fields that will be used to keep those 2 values
put the method inside that class
instantiate the class and call the method.
The only thing that will be changed in the method is that in the end it will assign those 2 values to the fields of the instance. Then I can address those values by referencing to the fields of that object.
Is it a good design and why?