Protocols and Records
Learn about the idea of protocols and polymorphism in Clojure.
What are protocols?
Clojure is a language that coexists in terms of abstractions with many implementations for them. In an object-oriented programming language, we know those abstractions as interfaces, and we’re able to implement and modify the algorithm for each implementation as many times as we want.
Protocols are the available features for abstraction and data structure definition with no compromises. They are essentially a collection of one or more polymorphic operations. Unlike multimethods (also of the polymorphism family), which perform dispatch on arbitrary values returned by a dispatching function, protocol methods are dispatched based on the type of the first argument.
Advantages
There are a number of reasons for using protocols:
They provide high-performance polymorphism as an alternative to interfaces. ...