Behaviors
Get familiarized with using a behavior for our interface having a dependency double.
We'll cover the following
Interfacing to external dependencies with behaviors
The interface that the SoggyWaffle.WeatherAPI
module provides is simple, as it’s made of just one function. However, if we expand the functionalities of the SoggyWaffle.WeatherAPI
module, it would be hard to keep SoggyWaffle.FakeWeatherAPI
up to date to mirror SoggyWaffle.WeatherAPI
. This situation is a great use case for behaviors, in which Elixir modules define a set of functions (an interface) that other modules can agree to implement.
We can define a behavior that specifies how we want to interface with the weather API and then implement that behavior both in the real weather API interface and the fake one.
Get hands-on with 1200+ tech skills courses.