Creating Module Behaviours

A contract sets the rules in an agreement between parties, and indicates how the parties will benefit. For example, think of a job contract. It has rules for the employee and the employer, and by following those rules both parties will reap specific benefits. If the rules are broken, though, those benefits aren’t guaranteed. In Elixir, a behaviour is a contract between a module and the client code that’s using it. It provides a common interface for a client across multiple modules. It means a client can use multiple modules in the same way since the modules provide the same functions with the same signatures defined in the behaviour contract. For example, Mix.Task is a behaviour. When we create a module that follows ...

Get Learn Functional Programming with Elixir now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.