Elixir Behaviours
in combination with Elixir Interfaces, this is how you get this “shared interface” in functional programming.
Difference with using
interface
?Ahh, I was confusing with the GraphQL interface through the Absinthe implementation. In GraphQL (which Absinthe implements in Elixir), interfaces define a shared set of fields that different types can implement.
https://elixirschool.com/en/lessons/advanced/behaviours
Sometimes you want modules to share a public API, the solution for this in Elixir is behaviours. Behaviours perform two primary roles:
- Defining a set of functions that must be implemented
- Checking whether that set was actually implemented
This is the behaviour we want to see:
Then, we can have the implementation