Elixir newbie here.

Hi. That’s a good question and something I might should have explained a little more detailed.

A behaviour in Elixir makes sure a module adhere to some contract (or interface if you like). The contract is defined by the @callback definitation, which defines that the behaviour has a single function. More callbacks could have been defined in the Behaviour module.

Not implementing the behaviour in a module that declares @behaviour MyApp.Mailer.Behaviour will give a compile-time warning like this:

warning: undefined behaviour function send_mail/1 (for behaviour MyApp.Mailer.Behaviour)

This makes it easy to define a contract and adhere to that contract. It is pretty much the same as interfaces in OO languages.

Like what you read? Give Lasse Ebert a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.