From Functions to OOP in Python: A Real App Example (Not Another Car/Factory Analogy)

From Functions to OOP in Python: A Real App Example (Not Another Car/Factory Analogy)

When I first started learning Python, I was completely comfortable writing functions.

Functions felt simple. They did the job. I could call them, pass some values, and get a result.

So naturally, I asked:

“Why should I use OOP (Object-Oriented Programming) when functions already work?” “Why complicate things with classes, self, and constructors like __init__()?”

If you’re also learning Python and wondering the same thing, you’re not alone.

Let me walk you through my thought process — not with abstract examples like cars and animals, but with something most of us use daily: a food delivery app like Zomato or Swiggy

🧠 The Beginner’s Mindset

When learning to code, we all write basic programs. You probably wrote a calculator, a to-do list, maybe even a small chatbot.

And in all those, functions were enough.

Example:

def place_order(user, item, price):
    print(f"{user} ordered {item} for ₹{price}")        

Call it :

place_order("Ravi", "Pizza", 250)
place_order("Sneha", "Burger", 150)        

Done! Easy. No self, no classes, no extra typing. And it works fine… until your app grows.

🚀 What Happens When Your App Grows?

Now imagine you’re building a real food delivery app.

It’s no longer just about printing the order. Now you want to:

  • Show order status: Placed, Preparing, Out for delivery, Delivered
  • Allow users to cancel orders
  • Track estimated delivery time
  • Store all orders and retrieve specific ones
  • Calculate total spending for a user

And more…

If you’re using only functions, suddenly things start getting messy.

You’ll need to:

-Pass more and more arguments to every function

-Manage separate lists/dictionaries to store each order’s data

-Write more logic just to find or update one order

It becomes hard to manage, reuse, and scale.

That’s where OOP (Object-Oriented Programming) saves the day.

💡 Enter: Classes and Constructors (__init__())

With OOP, you can model each order as an object.

Think of it like this:

🛍️ In the real world: Every order on Zomato is a package — it contains the user info, the item, the price, the status, and actions like cancel or track.

🧠 In OOP: Each object (created from a class) can store data and do actions.

Here’s how it looks in Python:

🧠 In OOP: Each object (created from a class) can store data and do actions.

Here’s how it looks in Python:


class Order:
    def __init__(self, user, item, price):
        self.user = user
        self.item = item
        self.price = price
        self.status = "Placed"

    def cancel(self):
        self.status = "Cancelled"
        print(f"{self.user}'s order cancelled.")

    def track(self):
        print(f"{self.user}'s {self.item} is on the way...")

    def summary(self):
        print(f"{self.user} ordered {self.item} for ₹{self.price}. Status: {self.status"}
        

Creating Orders :

order1 = Order("Ravi", "Pizza", 250)
order2 = Order("Sneha", "Burger", 150)        

Using there methods

order1.track()
order2.cancel()
order1.summary()        

Each order is now a real object. It stores its own data (user, item, price, status) and can perform its own actions (track(), cancel()).

🛠 Real App-Like Use Case

Let’s say we want to keep track of all orders in the app.

With OOP, it’s super clean:

all_orders = []

order1 = Order("Ravi", "Pizza", 250)
order2 = Order("Sneha", "Burger", 150)

all_orders.append(order1)
all_orders.append(order2)

# Print all order summaries
for order in all_orders:
    order.summary()        

And tomorrow if you want to add a new feature like discounts, just update the class:

class Order:
    def __init__(self, user, item, price, discount=0):
        self.user = user
        self.item = item
        self.price = price
        self.discount = discount
        self.status = "Placed"

    def final_price(self):
        return self.price - self.discount
        

👨💻 Real-World Relevance

Still not convinced?

Let me tell you something important: All major Python frameworks and libraries — whether it’s Flask, Django, PyTorch, TensorFlow, scikit-learn — use classes and constructors heavily.

Example in PyTorch:

class MyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer = nn.Linear(10, 1)

    def forward(self, x):
        return self.layer(x)        

Even though you may not write your own classes right away, understanding how they work is essential to use any real-world Python tool.

🎯 Final Thoughts

So here’s what I’ve learned:

  • Functions are great for simple tasks.
  • But when your app grows — with more features, users, and logic — OOP becomes necessary.
  • Constructors like __init__() help you set up your object’s data automatically.
  • It keeps your code cleaner, more organized, and scalable.

🗣️ What helped me understand it?

The moment I stopped thinking in terms of “Car has wheels” and instead thought “My food order has a user, item, price, and status” — OOP made sense. It felt natural.💬 What About You?

What was the real-life example that helped you understand OOP?

Drop your thoughts 👇 — let’s help more beginners learn by using relatable examples, not abstract ones.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

#Python #OOP #ObjectOrientedProgramming #FunctionsVsOOP #BeginnerToDeveloper #FoodDeliveryApp #LearnPython #100DaysOfCode #PythonForBeginners #ZomatoClone #SwiggyApp #TechLearningJourney

To view or add a comment, sign in

More articles by Hammad Razaa

Explore content categories