Polymorphism
Explore the concept of polymorphism in Elixir and how it supports the functional transition from object-oriented paradigms. Learn to use pattern matching for fixed cases and protocols for extensible polymorphism, while understanding best practices to avoid complexity in your code.
Polymorphism in Elixir
Sometimes, adopting a new language means letting go of features that we’ve grown to depend on. Even though Elixir decouples the concepts of data, behavior, and time, we still may argue in favor of other OO concepts like polymorphism. For example, in the previous lesson, we wrote this code:
We argued that .split("/"). last may be a source of confusion since we don’t know where methods like split come from. We might counter, “It’s not a bug. It’s a feature.”
In some situations, we don’t actually care which object has the function. We only care that it knows how to split("/"). That’s polymorphism. ...