Possible to have multiple behaviours?

Is it possible to define a behaviour that implements the callback requirements from another behaviour and on top of those some additional ones?

It’s very likely possible with some hacking but IMO not out of the box. Behaviours are basically Elixir’s idea of duck typing so they usually aren’t hierarchical.

Yes, you can implement as many behaviours as you like as long as their callback requirements do not collide.

1 Like

Yeah, I was going through the idea and thinking, well this, is OO - but in fact not really, you’re not defining the implementation just stating what a compliant behaviour must implement.

1 Like

But you mean, a given module can exercise multiple behaviours, but not that I can define a behaviour such that

defmodule MixedBehaviour do
  @callbacks_from_other_behaviour
  @callback this_module_callback1 :: any()
  #etc
end

I guess I can do __using__ and import both behaviours explicitly there? And then the implementer has to use use instead of @behaviour.