Chapter 14. Protocols, records, and types

 

This chapter covers

  • An overview of the expression problem
  • A custom solution to the expression problem
  • Clojure’s solution to the expression problem
  • A look at deftype, defrecord, reify

Abstraction is an important tenet of software development because it allows code that’s maintainable and extensible. Clojure itself is built on abstractions. For instance, most things in Clojure are coded to interfaces rather than being direct concrete implementations. This allows for reuse of code that expects those interfaces and allows the addition of more implementations to the mix.

Sooner or later, during your time on most projects, you’ll run into an abstraction-oriented issue known as the expression problem. It has to do with how to cleanly extend or use existing code—either something you wrote yourself or, more important, something you don’t own. Clojure’s approach to handling this issue is protocols. In order to get to this topic, though, we’ll first explore the problem in some depth. Then, we’ll come up with our own solution. Finally, we’ll explore protocols, data types, and the reify macro.

14.1. The expression problem

14.2. Modus operandi

14.3. Protocols and data types

14.4. Summary

sitemap