Junior — Middle
Can you explain the main differences between procedural programming style and object-oriented approach?
sobes.tech AI
Answer from AI
Procedural programming is based on a sequence of function or procedure calls that change the program's state through global or local variables. This style focuses mainly on algorithms and execution steps.
Object-oriented programming (OOP) is built around objects — entities that combine data and methods to operate on that data. The main principles of OOP are encapsulation, inheritance, and polymorphism, which allow for creating more flexible and extensible programs.
Example:
// Procedural style
int sum(int a, int b) {
return a + b;
}
// Object-oriented style
class Calculator {
int sum(int a, int b) {
return a + b;
}
}