Protocols

There's a big problem in software. You've got all these different types, and all of these different roles they play in your software. But sometimes you can't modify the code for the type. Maybe it's in a Java class in a library. Clojure's protocols let you solve this. You can extend existing classes or build protocols into new types.

When you have different types filling the same roles, we call that polymorphism. Clojure uses protocols for polymorphism. They are totally extensible on "both ends". You can extend existing types with new roles. And you can fill existing roles with new types. They let you create very flexible software with little effort.

In this course, you will learn:

  • What problem protocols solve (it's called "The Expression Problem")
  • How to define new protocols
  • How to extend types with protocols
  • Three cool uses for protocols