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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access