Other than lack of documentation, what is the difference between definterface
and defprotocol
in Clojure?
According to the Joy of Clojure:
The advantages of using
definterface
overdefprotocol
are restricted entirely to the fact that the former allows primitive types for arguments and returns. At some point in the future, the same advantage will likely be extended to the interfaces generated [by protocols], so usedefinterface
sparingly and prefer protocols unless absolutely necessary.
My possibly incomplete understanding was definterface
produces an interface .class that java code can implement in order to create classes suitable to pass to your Clojure functions.
Protocols are, in short, a faster and more focused way of doing dispatch than multimethods. you actually have running code in a protocol that is used by other clojure code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With