Currency Exchange Groups
In the Currency Module design, currency exchange groups are responsible for creating exchange objects that contain a particular implementation. A currency exchange group attempts to create an RWExchange object when presented with a source currency, a target currency, and an exchange rate table. It uses the source and target currencies to search the exchange rate table described in Exchange Rates and Exchange Rate Tables for the exchange rates the particular implementation needs.
The Currency Module includes three currency exchange groups: RWEuroGroup, RWMultiplicationGroup, and RWDivisionGroup. Although they all produce exchange objects, they work slightly differently.
When an RWEuroGroup object is presented with source and target currencies and an exchange rate table, it determines whether both currencies are contained in its list of Euro currencies. If both currencies are in the Euro list, the RWEuroGroup object searches the exchange rate table for two conversion rates: one from the Euro to the source and a second from the Euro to the target. If both rates are found, it creates an exchange object with an RWTriangularExchange implementation.
When an RWMultiplicationGroup object is presented with source and target currencies and an exchange rate table, it searches the exchange rate table for a source-to-target conversion factor. If it finds one, it creates an exchange object with RWMultiplicationExchange implementation. Similarly, when an RWDivisionGroup object is presented with source and target currencies and an exchange rate table, it searches the exchange rate table for a target-to-source conversion factor. If found, it creates an exchange object with RWDivisionExchange implementation.
Notice that while an RWEuroGroup pre-checks a list of currencies to see whether the currencies presented to it are members of that group, the multiplication and division group objects don’t do any such pre-check.
Note that the exchange group creates an invalid exchange object if it cannot create a valid one.