What's correct Erlang way to have separated implementations from the contract and how to switch between them?
While others mention the behaviour feature, it is merely a small helper to make sure you implement all functions in a module for a callback structure. If you have two implementations, a
and b
, and both implements the same functions, you can just statically substitute a
for b
in a calling module. For static configuration where you have a better implementation, this is preferable.
If the question is of a more dynamic nature, you can just do
Mod = a,
Mod:f(Args).
And then in code set Mod
appropriately. This lets you dynamically control what module to call while the program is running. It is not entirely clear which of the two you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With