Table of Contents
Did you know all of the software problems or use cases we solve using object-oriented programming style can also be solved using Functional programming?
Yes, 100% of all use cases that can be solved using object-oriented can also be solved using functional programming. The best thing is to decide which one is suited for our use-case when writing/designing a use-case.
First of all, functional and object-oriented programming are not opposites. They both will be used alongside.
You need to understand that object-oriented programming is an imperative programming style, whereas functional programming is a declarative style.
Before we jump directly into functional programming, example code snippets, etc., think about what problems it is here to solve in Java.
Problem it solves
One of the biggest advantages of using functional programming is that it reduces code bugs and improves reusability.
So, for pure functions, it always returns the same result/output given the same input arguments.
Functions are not called pure if they change the object's state internally or externally.
The benefit of using a Functional Programming style in Java is that the side effect of a mutable input can be avoided.
How Functional Programming (FP) Gained Popularity?
In object-oriented programming, we bring the data(state) and behavior (methods) that operate on a single unit called objects.
We think that data and methods are different in Functional Programming, so we keep them separate. That’s the major difference between these two programming paradigms.
There are few places where object-oriented falls short or doesn’t provide much guidance, and in these precise areas, functional programming can step in and help.
Gopi Gorantala Newsletter
Join the newsletter to receive the latest updates in your inbox.