Wiki: Functional OOP, Clojure style
For agents: Markdown version · Wiki index · Explore
- Speaker: Yoav Rubin
- Event: Reversim Summit 2013
- Video: https://www.youtube.com/watch?v=GOAX1ypl2jc
- Transcript: /transcripts/2013/04-GOAX1ypl2jc.md
- Language: Hebrew and English · Type: talk · Level: intermediate
- Topics: Software Engineering, Functional Programming
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 Software can be modeled as a matrix where rows are data types and columns are API operations.
- 4:35 Clojure organizes projects into namespaces, allowing functional information hiding.
- 5:38 Clojure provides type and record meta-objects for defining custom data types.
- 10:02 Protocols in Clojure decouple the definition of an API from its implementation across data types.
- 12:02 Multi-methods enable functional polymorphism by utilizing user-defined dispatching functions.
- 14:16 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