Joachim, Thanks for the tips. I saw the Unit package was following the same pattern you are describing. My first though was to use ScaledDecimal, but I discovered it is pretty slow with computation (amortization schedule, search for rate) but there are workarounds for that.
Hilaire Le 11/01/2015 10:36, Joachim Tuchel a écrit : > There are more arguments against Subclassing any Number class: > > Exchange rates are two-way most of the times. It is not only USD->EUR, > but also the other way round. This is not the responsibilty of a number. > > For more information, I recommend Martin Fowler's Analysis Patterns book > (old, but not dated at all!). > > Joachim > > > Am 11.01.15 um 10:31 schrieb Joachim Tuchel: >> Ah, I just saw on second reading that you want to implement something >> for currency exchange rates, not MonetaryAmounts. Still, don't use >> Float, use ScaledDecimal or FixedPoint and make sure it NEVER contains >> a Float. You'll get into all kinds of strange problems, starting with >> Imports from datasources like Yahoo or whatever. >> >> I'd subclass Object, and make the new class hold the exchange rates as >> a ScaledDecimal with a well-defined scale (like 4 or 6 or even 8 >> digits if you want). >> >> Joachim >> >> >> >> >> Am 11.01.15 um 10:28 schrieb Joachim Tuchel: >>> Hilaire, >>> >>> unless you have very (very very) specific needs, I would strongly >>> discourage you to use Float for anything related to Money or >>> Percentages. >>> >>> We use a subclass of Object for MonetaryAmounts and implemented most >>> of the protocol of Magnitude. But, most importantly, the amount >>> instVar is made sure to always hold instances of ScaledDecimal (in VA >>> Smalltalk, that is). >>> >>> Joachim >>> >>> Am 11.01.15 um 10:25 schrieb Hilaire: >>>> Le 11/01/2015 09:06, stepharo a écrit : >>>>> Hilaire >>>>> >>>>> what is your requirement? >>>>> >>>>> Stef >>>> >>>> I want to create a currency object, basically a Float with an attribute >>>> to specify the currency unit. >>>> >>>> Hilaire >>>> >>>> >>> >>> >>> >> >> >> > > > -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
