OO design patterns vs FP idioms in Java 8

Millies, Sebastian Sebastian.Millies at softwareag.com
Wed Oct 2 01:06:55 PDT 2013


Hi there,

has anyone written about the relation of OO design patterns (by which I mean the usual GoF patterns) to functional programming idioms that may be applicable in Java 8? The reason I ask is that I think it's possible that ideas from FP may inform our approach to design patterns in the new Java release. I have searched Google a bit, but found no really coherent discussion.

Much of it just boils down to higher order functions. For example, it seems obvious that Decorator (and Chain of Responsibility and Adapter, too) are forms of functional composition. Strategy is just passing a lambda that implements the concrete strategy.

But other patterns are more complicated. Visitor is often cited as being fold, which is almost reduce in separating the traversal, in this case of a stream, from the algorithm operating on the stream elements. But would this carry over to other structures than streams in Java 8?

Some typical FP things would clearly be inappropriate in Java. Obviously, Java is not being transformed into Haskell, and I don’t expect to use monadic programming  instead of throwing exceptions ;-) However, other FP ideas may now be really viable in Java.

I suspect this might be off-topic for this list, as it’s a bit speculative. But I find the question just naturally suggests itself.


n  Sebastian

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com



More information about the lambda-dev mailing list