OOP versus Type Classes in Scala
summary
Compares OOP’s single-dispatch subtype polymorphism (good for resource management, encapsulation and hiding implementation) with type classes as compile-time dictionaries that enable extension, automatic instance derivation via shapeless or magnolia, and practical uses like JSON serializers, a collection-builder sequence implementation, a pure iterator expressed as a state monad, and a safe-logging type class. Shows failures too: monads can’t cleanly become OOP data constructors, f‑bounded polymorphism is awkward, and warns type classes must be coherent and must not keep state. Use OOP for resources and type classes for serialization and data construction.
AI-written summary · about
chapters (13)
- 0:00Start
- 4:35Abstraction
- 6:04The Black Box Abstraction
- 9:57Subtype Polymorphism
- 13:38Parametric Polymorphism
- 17:30Type Classes
- 20:47Resource Management
- 23:47Type Class Super Powers
- 31:00Design Patterns
- 31:46Use Type Classes for Data Serialization
- 39:27Type Classes Must Not Keep State
- 40:35Add the Environment
- 47:36Output Errors
related talks
48mObject Functional Programming
31mTYPECLASSES — A TYPE SYSTEM CONSTRUCT
20mType Classes for the Rest of Us
41mPolymorphism in Scala
31mType-Classes (in Scala 3)
45mHow to be polymorphic in Scala
58mSeparating Behavior and Data with Type Classes in Scala
35mIntroducing Typelevel Scala into an OO environment
