A way to return multiple return values from a method: put method inside class representing return value. Is it a good design?
        Posted  
        
            by 
                john smith optional
            
        on Programmers
        
        See other posts from Programmers
        
            or by john smith optional
        
        
        
        Published on 2012-10-01T11:52:41Z
        Indexed on 
            2012/10/01
            15:52 UTC
        
        
        Read the original article
        Hit count: 404
        
java
|design-patterns
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?
© Programmers or respective owner