Currency repository
Sharom opened this issue · 4 comments
To be able to work with predefined set of currencies in an application — we should receive a currency from some repository by a code of currency.
So, we need some interface for repository of currencies. For example:
abstract class Currencies {
Currency getOf(String code);
bool contains(Currency currency);
bool containsOf(String code);
List<Currency> toList();
}
And it's possible to provide implementations like IsoCurrencies
and CascadeCurrencies
as a part of library.
But I can't solve: should find()
method return null
when currency cannot be found or it's better to throw an exception…
If it indicates a bug in the application then IMHO it should be an exception. If it's common that the currency couldn't be found, I'd return null
.
I think users of the API shouldn't need to use try/catch
for normal program flow, only to catch unexpected behavior.
Seems an error is better if it's a misuse of the API
https://api.dartlang.org/stable/1.20.1/dart-core/Error-class.html
https://api.dartlang.org/stable/1.20.1/dart-core/Exception-class.html