Behaviours

Get a brief overview of behaviours in Elixir.

When we wrote our OTP server, we wrote a module that started with the following code:

defmodule Sequence.Server do 
  use GenServer
  ...

In this chapter, we’ll explore what lines such as use GenServer actually do and how we can write modules that extend the capabilities of other modules that use them.

An Elixir behaviour is nothing more than a list of functions. A module that declares that it implements a particular behaviour must implement all of the associated functions. If it doesn’t, Elixir generates a compilation warning. We can think of a behaviour definition as being like an abstract ...