On 12/18/2012 8:22 AM, Chris Uppal wrote:
> Arne Vajhøj wrote:
>
>> B)
>>
>> request.setWeight(MILLIGRAMS_PER_GRAM * response.getWeight());
>
> While I'll grant that your (B) is OK, I'd point out that if you are mixing mg
> and g in the same program then you are already in a state of sin.
>
> Given that that might be necessary (and anyway sin is acceptable these days 
> I'd want to be lot more explicit.
>
> request.setWeightMg(1000 * response.getWeightG());
That was #D.
I do not like that due to the pollution of the method names.
> or better yet:
>
> request.setWeightInMg(convertGtoMg(response.getWei ghtInG());
I still do not like the polluted set and get names.
But the conversion method is certainly a solution.
And the constant in that method may not require the named constants.
> Or just go the full OO hog:
>
> request.setWeight(response.getWeight());
>
> And leave it to the Request, Response, and (in particular) the Weight classes
> to sort out mutually convenient units and conversions themselves
I don't think that would be very practical, because one of the classes
would have a method using a different unit than the rest of the class.
Arne