Chapter 14. Functional Design Patterns
Functional programming’s answer to object-oriented design patterns is usually “just use functions instead.” Technically, that’s correct; it’s turtles all the way down1 with functional programming. However, coming from an object-oriented mindset wanting to augment your code with functional principles, more practical advice is required to utilize known patterns in a functional fashion.
This chapter will examine some of the commonly used object-oriented design patterns described by the “Gang of Four,”2 and how they can benefit from a functional approach.
What Are Design Patterns?
You don’t have to reinvent the wheel every time you need to solve a problem. Many of them have already been solved, or at least a general approach to a fitting solution exists in the form of a design pattern. As a Java developer, you most likely used or came across one or more object-oriented design patterns already, even if you didn’t know it at the time.
In essence, object-oriented design patterns are tested, proven, formalized, and repeatable solutions to common problems.
The “Gang of Four” categorized the patterns they describe into three groups:
- Behavioral patterns
-
How to deal with responsibilities of and communication between objects.
- Creational patterns
-
How to abstract the object creation/instantiation process, to help create, compose, and represent objects.
- Structural patterns
-
How to compose objects to form larger or enhanced objects.
Design patterns ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access