About 1902 letters

About 10 minutes

#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:

  1. Open the refrigerator door
  2. Put the elephant inside
  3. 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.

refrigerator elephant elephant refrigerator refrigerator attributes: Contents methods: open_door() close_door() take_out() store()

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

Created in 5/15/2025

Updated in 5/15/2025