defprotocol
: defines an interfacedeftype
: create a bare-bones object which implements a protocoldefrecord
: creates an immutable persistent map which implements a protocol
Typically you'll use defrecord
(or even a basic map
);
unless you need some specific Java inter-op,
where by you'll want to use deftype
instead.
Note:
defprotocol
allows you to add new abstractions in a clean way Rather than (like OOP) having polymorphism on the class itself, polymorphic functions are created in namespaces. Meaning different namespaces can implement different functionality
@kenfehling
reify
is for the case where you want to create an anonymous implementation of a protocol, which is useful for creating local overrides. See the coupon example in the docs forreify
or, for a more systematic example, see the implementation of the Om framework, which uses it as a way to override React lifecycle hooks in custom components.