Object oriented programming

I’ll be downright honest. I’m no computer geek. I don’t dream in algorithms and live through my day in code. If someone had shown me a snippet in java last year, I’d have thought of it as some not so artistic poem. But then again, life signed me up for a compsci degree as I grumbled away.

I had two options. Be miserable and curse away in metaphors no one understood OR create something incredible to survive, using metaphors everyone understood. I chose the latter. (Though I still am miserable and I DO bash the system under poetic phrases, at least I can pull off a passing grade easily with this.)

Surviving in 2025 means learning to use AI. I owe ChatGPT my life, for it helped me learn in a way never imaginable. And now, because I figured there would be many fellow mates round the world frantically trying to mug up the syllabus at two the night before the exam. So, I wrote prompts after prompts trying to design the best structure. After a million tries, here’s what I got. Of course as a writer I couldn’t help but rewrite the literary parts, the style and dialogues keeping the technical details intact.
(For the sake of it, started with 10th grade ICSE compsci.)


Alohomora! Welcome to Hogwarts School of Witchcraft and Coding.

Professor Codewick entered the classroom with a stack of scrolls. “Wands out, parchment ready! Today, we’re not casting spells, but something even more powerful-understanding the magical thinking in computers!”

 # Introduction: Procedural vs Object-Oriented Programming

 Procedural-Oriented Programming (POP):

Like following a recipe in Potions class.

  • Code is written like a sequence of spells, line after line, like a potion’s recipe.
  • Focus is on functions and procedure calls.

“Like brewing a potion with everyone dipping their spoons into the same cauldron.”

  • Functions share global ingredients (data).
  • Ingredients (data) move freely from step to step, like an open recipe.
  •  Anyone can change the potion — no restrictions.
  •  Hard to fix when it goes wrong.
  •  Can’t reuse the recipe easily.
  •  Examples: BASIC, COBOL, FORTRAN.

Ron (grumbling):
“So basically, you do this, then that, and then pray it doesn’t explode.”

“Well…yeah. Did you actually listen? Didn’t know you could listen.” laughed Hermione, thick with sarcasm.

Object-Oriented Programming (OOP):

Like building magical objects that know how to act by themselves.
“Create magical beings, give them wands and rules, and let them decide what to do.”

  • Focuses on objects (like magical creatures) that contain both data and behaviours.
  • Reusable. Instead of rewriting everything, you reuse spells built into magical objects.

Like enchanted potion bottles — sealed, self-stirring, and protected by magic,” went on Professor Codewick nodding his head aggressively.

  • Each object stores its own ingredients (data) and spells (functions).
  • Only the object itself can use or modify what’s inside.
  •  Safer — no random tampering.
  •  Easier to fix errors — fewer potion explosions.
  • Great for handling complex magical systems.
  •  Examples: Java, C++, Python.

Hermione (adjusting her prefect badge):
“So in OOP, instead of just casting spells blindly, we teach the objects how to act. A unicorn knows how to run; you don’t have to explain it every time!”


# The Four Pillars of Object-Oriented Programming

Professor Codewick waves his wand. Four glowing pillars rise from the floor; each marked with ancient Muggle runes.

1. Data Abstraction: The Cloak of Simplicity

“Only show what’s important. Hide the messy cauldron bits.”

  • Just like a spellbook only shows incantations, not how the wand’s core functions.
  • In OOP, abstraction hides internal details and shows only the necessary features to the user.


“Wait- I just wave my wand and it works? I don’t need to know all the wandlore inside?” asked Neville stunned.

“Oh yes!” called a dreamy voice suddenly. Luna joined them, her eyed glued to an upside-down book.

“Just like people don’t always ned to know everything in our hearts. Let our tongue be a royal lady and reflect only the significant bits, smartly leaving out the cluttered mess within.”

She wasn’t lying. No matter how weird, she spat facts.


2.  Encapsulation: Potion Bottling for Code

“Bundle data and spells together and seal them with a cork.”

  • Encapsulation means wrapping data and functions into one class.
  • Like keeping all ingredients and instructions inside a potion bottle. No one messes with it from the outside.

 “You don’t want Peeves tampering with the potion ingredients, do you?” smirked Professor Codewick.


3. Inheritance: The Magical Family Tree

“A Hippogriff inherits traits from a Griffin and a Horse.”

  • Inheritance allows one class to derive properties from another; like magical creatures or spells evolving from older ones.
  • Promotes code reuse. Child classes use the parent’s code without rewriting it.
  • Takes lesser memory for storage.
  • Imagine using a Polyjuice potion. It works fast and no need to create a whole new person, just some toenails inherited achieve the results.

4. Polymorphism: One Spell, Many Effects

“‘Expelliarmus’ works differently in different duels.”

  • Polymorphism means one function behaves differently depending on the object.
  • The same method can be overridden in different classes to perform context-specific behaviour.

 “Same word, different results you mean?” remarked harry studying the pillars.

“Just like saying ‘sorry’ to Snape vs to Hagrid,” muttered Ron under his breath.

As they let out muffled giggles, the pillars disappeared. Professor Codewick went invisible behind a pile of scrolls as he headed out the class yelling something about homework and lessons.

I still find this only as interesting as Professor Binns’ lecture, but I could play around with a computer spell or two if that meant learning at Hogwarts.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *