Intern — Middle
Are you familiar with principles of programming in the functional or object-oriented paradigm?
sobes.tech AI
Answer from AI
Yes, I am familiar with the principles of both programming styles.
Object-oriented programming (OOP) focuses on modeling objects with state (fields) and behavior (methods). The main principles are encapsulation, inheritance, polymorphism, and abstraction.
Functional programming (FP) emphasizes pure functions, immutability, and the absence of side effects. FP facilitates parallelism and testing.
Example in Python demonstrating both approaches:
# OOP
class Calculator:
def __init__(self, value=0):
self.value = value
def add(self, x):
self.value += x
calc = Calculator()
calc.add(5)
print(calc.value) # 5
# Functional style
def add(x, y):
return x + y
result = add(0, 5)
print(result) # 5