Result class dependency

Posted by Stefano Borini on Programmers See other posts from Programmers or by Stefano Borini
Published on 2011-03-18T12:48:51Z Indexed on 2011/03/18 16:18 UTC
Read the original article Hit count: 323

Filed under:

I have an object containing the results of a computation. This computation is performed in a function which accepts an input object and returns the result object.

The result object has a print method. This print method must print out the results, but in order to perform this operation I need the original input object. I cannot pass the input object at printing because it would violate the signature of the print function. One solution I am using right now is to have the result object hold a pointer to the original input object, but I don't like this dependency between the two, because the input object is mutable.

How would you design for such case ?

© Programmers or respective owner

Related posts about design