Linked by Bjorn Raupach on Thu 17th Jul 2008 06:01 UTC
Java Today was one of those days when I wished Java would support multiple return values. I had to develop a rather CPU-intensive algorithm which would compute a solution for a knotty constraint problem. Having a solution alone is sometimes not enough and you also need to add some parameters which measure the quality of the computed outcome. Most of these accompanying parameters can or have to be computed within the algorithm itself, but Java allows you to return only one value either an object or a primitive type. People working with Lisp, MATLAB or Perl, just to mention a few, don't have a problem like this at all. Functions supporting multiple return values is already implemented at the language level and frameworks make heavy use of this. But as a Java programmer you are pretty much stuck here and need to consider some other means to come out of this situation. In the following I would like to give some hints on that topic. Hopefully they are of help for anyone having the same problem every now and then.
E-mail Print r 1   · Read More · 65 Comment(s)
Permalink for comment 323504
To read all comments associated with this story, please click here.
Member since:

I think it's pretty clear from reading this article that you have very little experience in solid object oriented design. No developer worth his salt would implement a generic "two return value" wrapper like that. If you have a set of related information that gets returned, the proper way to handle it is to design a class that represents that object, and contains methods to analyze its data.

The solution you suggest is an arbitrary pairing of potentially unrelated data in a too-generic fashion, from which no meaning can be derived - and is therefor a horrible design.

Right. Classes like Point, PairOfShoes, Triangle, ... instead of TwoReturnValues and ThreeReturnValues. And if the values don't relate the method should get refactored.

Reply Parent Score: 2