Behaviours are a list of functions specifications that another module can implement. They are similar to interfaces in other languages.
If you’ve used the
use
keyword when writing GenServers or in the Phoenix framework, you’ve already used behaviours.
Here’s an example behaviour:
And a module that implements it:
The @behaviour
module attribute above indicates that this module is expected to define every function defined in the Parser
module. Missing functions will result in undefined behaviour function
compilation errors.
Modules can have multiple @behaviour
attributes.