Behaviours define callbacks & protocols define methods without signatures. Modules implementing a protocol should give definition for all those methods. Same for modules
Protocol is type/data based polymorphism. When I call Enum.each(foo, ...)
, the concrete enumeration is determined from the type of foo
.
Behaviour is a typeless plug-in mechanism. When I call GenServer.start(MyModule)
, I explicitly pass MyModule
as a plug-in, and the generic code from GenServer
will call into this module when needed.