# Functional OOP, Clojure style

- Speaker: [Yoav Rubin](/wiki/speakers/yoav-rubin.md)
- Event: [Reversim Summit 2013](/wiki/years/2013.md)
- Video: https://www.youtube.com/watch?v=GOAX1ypl2jc
- Transcript: [/transcripts/2013/04-GOAX1ypl2jc.md](/transcripts/2013/04-GOAX1ypl2jc.md)
- Language: Hebrew and English · Type: talk · Level: intermediate
- Topics: [Software Engineering](/wiki/topics/software-engineering.md), [Functional Programming](/wiki/topics/functional-programming.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

This talk explores how object-oriented programming concepts can be achieved in a functional language using Clojure. The speaker uses a matrix model of types and functionalities to compare traditional object-oriented programming with Clojure's approach. The audience learns how to implement encapsulation, polymorphism, and inheritance through data structures, protocols, and multi-methods.

## Key points

- [1:08](https://www.youtube.com/watch?v=GOAX1ypl2jc&t=68s) Software can be modeled as a matrix where rows are data types and columns are API operations.
- [4:35](https://www.youtube.com/watch?v=GOAX1ypl2jc&t=275s) Clojure organizes projects into namespaces, allowing functional information hiding.
- [5:38](https://www.youtube.com/watch?v=GOAX1ypl2jc&t=338s) Clojure provides type and record meta-objects for defining custom data types.
- [10:02](https://www.youtube.com/watch?v=GOAX1ypl2jc&t=602s) Protocols in Clojure decouple the definition of an API from its implementation across data types.
- [12:02](https://www.youtube.com/watch?v=GOAX1ypl2jc&t=722s) Multi-methods enable functional polymorphism by utilizing user-defined dispatching functions.
- [14:16](https://www.youtube.com/watch?v=GOAX1ypl2jc&t=856s) The derive mechanism allows establishing inheritance relationships between types in multi-methods.

## Takeaways

- Use protocols to separate API definitions from data types for better modularity.
- Leverage multi-methods when dispatch logic needs to be custom-tailored beyond simple type matching.
- Be cautious with global state modifications such as derive in multi-methods to avoid side effects.

## Questions this talk answers

- How does Clojure handle polymorphism without traditional class-based inheritance?
- What is the difference between using protocols and multi-methods in Clojure?
- How can you extend existing data types with new interfaces without recompiling code?

## Technologies

Clojure, Java, JVM, JavaScript, Python

## Tags

clojure, design patterns, functional programming, object oriented programming, polymorphism
