#Object-Oriented Programming (OOP) Explanation
Object-Oriented Programming (OOP) is a very popular programming paradigm that organizes code around objects as the fundamental units.
For example, consider the question: "How do you put an elephant into a refrigerator?" A straightforward procedure would be:
- Open the refrigerator door
- Put the elephant inside
- Close the refrigerator door
In procedural programming, this can be represented as:
open_door(refrigerator) store(refrigerator, elephant) close_door(refrigerator)
This approach is called Procedure-Oriented Programming (POP), where the basic unit is the procedure.
Using the object-oriented mindset, the problem is decomposed into interacting objects: a “refrigerator” object and an “elephant” object. The refrigerator can perform operations such as opening the door, closing the door, storing items, and retrieving items.
The flow in OOP still follows a process:
refrigerator.open_door() refrigerator.store(elephant) refrigerator.close_door()
But the code modules are organized around related responsibilities — for example, refrigerator.open_door()
only handles the refrigerator door, not some other door like a TV door.
Summary:
- Procedural programming is simpler and aligns with intuitive step-by-step thinking.
- Object-oriented programming better models real-world physical structures by bundling data and related behavior inside objects.
Reference: Object-oriented programming - Wikipedia