amnu3387
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?
First Post!
dimitarvp
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.
Most Liked
hauleth
Yes, you can implement as many behaviours as you like as long as their callback requirements do not collide.
amnu3387
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.
Last Post!
amnu3387
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









