Get your ticket to attend. Join event to build your agenda.

OOP versus Type Classes in Scala

- PST
Joy
Join Stream

Software developer, author of Monix, Typelevel contributor, focused on building low-latency, high-throughput web services, Scala, Haskell, and functional programming enthusiast.


Scala is a hybrid OOP+FP language. If you love OOP, Scala is one of the best static OOP languages. But Scala also exposes parametric polymorphism and can encode type classes.

Thus, developers can also choose to use parametric polymorphism restricted by type classes (aka ad hoc polymorphism). As if choosing when to use immutability versus object identity wasn't bad enough, developers are also faced with a difficult choice when expressing abstractions. Such choices create tension in teams, with the code style depending on the team leader or whoever does the code reviews.

Let's go through what is OOP, what is ad hoc polymorphism via type classes, how to design type classes, go through the pros and cons, and establish guidelines for what to pick, depending on the use case.