Funcional v / s orientado a objetos

Gato pega um pássaro e o come

Orientado a Objeto

class Bird
class Cat {
def catch(b:Bird): Unit = ...
def eat(): Unit = ...
}
val cat
= new Cat
val bird
= new Bird
cat
.catch(bird)
cat
.eat

Funcional

trait Cat
trait
Bird
trait
Catch
trait
TummyFull

def catch(hunter: Cat, prey: Bird): Cat with Catch
def eat(consumer: Cat with Catch): Cat with TummyFull

val story
= (catch _) andThen (eat _)
story
(new Cat, new Bird)

Cortesia Scala em profundidade