amnu3387

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

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

hauleth

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

amnu3387

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

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.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement