Earlier quoted context omitted.
Ok simple question. Have a method called increment(n) on an object called tracker. It’s used to increment tracking id values. I want to reuse the logic of increment(n) inside another object called childHeight to increment height values. Can I import the method and reuse it inside another object? No. I can’t. But if increment was a pure function thats like this increment(c, n) then I can move it anywhere. That is what…
There are multiple ways to handle that. Class Number { static Int inc(Int n) { return n+1 } } import static Number.inc Class Tracker { Integer height = 0; incHeight() { this.height = inc(this.height) } } class Tracker extends Numbers { Integer height = 0; incHeight() { this.height = this.inc(this.height) } } Or interface Number { default Int inc(Int n) { return n+1 } } class Tracker implements Numbers { Integer heigh…
With functional you don’t rewrite. You recompose what you already have.
It means oop is not modular. You didn’t create modules that can be reused. Nothing could be reused so you had to reconfigure everything.