Sobes.tech
Junior — Middle

What are the key differences between object-oriented and functional programming styles?

sobes.tech AI

Answer from AI

Object-oriented style (OOP) and functional programming style have fundamental differences:

  • OOP is based on modeling entities as objects with state (fields) and behavior (methods). Main concepts: encapsulation, inheritance, polymorphism.
  • Functional programming focuses on computations through functions that have no side effects and do not change state. Main concepts: pure functions, immutability, higher-order functions.

In Java, for example, OOP is the classic model with classes and objects, while functional style is implemented through lambdas, streams, and functions from the java.util.function package.

Example of a functional approach in Java:

List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
List<Integer> doubled = numbers.stream()
    .map(n -> n * 2)
    .collect(Collectors.toList());
What are the key differences between object-oriented… - sobes.tech