LitGroup/money.dart

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.

@zoechi So, it's better to throw an error instead of exception.

@zoechi Ok. I will use an exception. What do you think about the name of method? getOf(code) or findOf(code)?