Using Function Composition

The OOP paradigm helps us realize abstraction, encapsulation, and polymorphism; inheritance is the weakest link in the paradigm. When programming in the functional style we compose higher-order functions, and as much as possible, promote immutability and functions. We can leverage our experience with OOP, and at the same time use the elegant functional style that is new in Java.

Let’s get a feel for object transformation. Suppose we need change, and we ask a friend to break a $10 bill. We don’t expect our buddy to tear up the bill and return the pieces. Instead, we’d like the bill to disappear into our friend’s pocket and some smaller bills to appear. Mixing OOP and functional style is like that; we send lightweight ...

Get Functional Programming in Java now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.