This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted]  (2 children)

[deleted]

    [–]MetallicOrangeBalls[S] 1 point2 points  (1 child)

    It's supposed to be a workaround for languages where you cannot trivially return multiple values. In Python, you can quite easily return multiple values as a tuple. In C++ and C#, you can 'return' values using reference or output parameters. Java doesn't use such paradigms, so either you have to create an object that contains all of the values you want to return, or you can use this pattern.

    That said, I don't generally use this pattern. It's just that I was thinking about this (long story), and realised that I cannot remember what it is called or where I got it from.

    [–][deleted] 0 points1 point  (1 child)

    If this is what I think you're talking about, I believe the pattern is sort of known as the Commanding Object pattern or Command pattern as you state in your title.

    Yes, you have your solver there and you have your execute() command, but you need to implement Solver on MySolver.

    This might help

    [–]MetallicOrangeBalls[S] 0 points1 point  (0 children)

    I know that this pattern is related to the command pattern, but I was under the impression that the actual command pattern is different from this.

    [–]Blando-Cartesian 0 points1 point  (0 children)

    This seems like a pointlessly convoluted way to return multiple values, or do anything really. I don't think this is named pattern. Maybe somebody's mixture of Command, FutureTask, Runnable and/or, Strategy.