Software Design

OOP: What Is It and How Does It Differ from Procedural Code?

There's a phrase you'll inevitably encounter while studying programming.

4 min read
Cover image for OOP: What Is It and How Does It Differ from Procedural Code?

What Is Object-Oriented Programming (OOP), and How Does It Differ from Procedural Programming?

There’s a phrase you’ll inevitably encounter while studying programming.

“This should be written in an object-oriented way.”

It sounds daunting at first. What is procedural programming, and what makes object-oriented programming so different? It’s not easy to get a feel for it.

Here’s the bottom line. Procedural programming focuses on “what should happen in what order,” while object-oriented programming emphasizes “who is responsible for the work.” The difference is whether data and the functions that operate on it are kept together or separate.

This article explains the difference through a simple coffee-ordering analogy and shows how the two approaches differ in real code.


Procedural Programming Is a Cooking Recipe

As its name suggests, procedural programming focuses on procedures—in other words, sequence.

You have data and separate functions that process it. Execution flows from top to bottom in order.

A cooking recipe is a perfect analogy: wash the ingredients, chop them, stir-fry them, and plate them. Translating that sequence directly into code is procedural programming.

Let’s look at a simple account example.

var balance = 10000  // Data

func deposit(amount: Int) {   // Functions kept separate
    balance += amount
}

deposit(amount: 5000)
print(balance)
// Output: 15000

The balance data is exposed externally, and the deposit function modifies it directly.

For a small program, this is actually simpler and faster. The problem appears as the program grows.

When there are 100 accounts and balance-modifying functions are scattered everywhere, tracking where a value changed becomes extremely difficult.


What Is Object-Oriented Programming (OOP)?

Object-oriented programming bundles data and functionality together. This bundle is called an “object.”

For an account, that means putting the “balance” data and the “make a deposit” functionality into one unit.

Let’s turn the account from earlier into an object.

class Account {
    private var balance = 10000   // Hide data inside

    func deposit(_ amount: Int) { // Include the functionality too
        balance += amount
    }
    func show() { print(balance) }
}

let myAccount = Account()
myAccount.deposit(5000)
myAccount.show()
// Output: 15000

balance is now hidden as private. External code can no longer change the balance arbitrarily; it can access it only through defined paths such as deposit.

That’s the core of object-oriented programming: protecting data and making it clear “who is responsible for the work.”

Think of ordering coffee this way. Procedural programming means I grind the beans, boil the water, and do everything myself. Object-oriented programming means delegating with “Barista, an Americano, please.” The barista object is responsible for knowing how to make it.


Four Core Characteristics of OOP

Object-oriented programming has four pillars. The terms may sound difficult, but the concepts are simple.

  • Encapsulation: hide data and allow access only through defined paths (like private above)
  • Inheritance: reuse functionality by inheriting it from an existing class
  • Polymorphism: the same command behaves differently for each object
  • Abstraction: hide internal complexity and expose only what is needed

Polymorphism is especially powerful. Tell something to “cry,” and a dog says woof while a cat says meow. The command is the same, but each object responds differently on its own.

One Account object handles both the balance and deposits
One Account object handles both the balance and deposits

When Should You Use OOP, and When Is Procedural Programming Better?

Object-oriented programming isn’t always the right answer. Choose based on the situation.

Situation Best fit
Short scripts, one-off calculations Procedural programming
Simple, sequential data flow Procedural programming
Large projects that continue to grow Object-oriented programming
Code developed collaboratively by multiple people Object-oriented programming
Similar concepts appear repeatedly Object-oriented programming

For small, simple tasks, procedural programming is often cleaner. For large, complex code that must be maintained over time, object-oriented programming shines.

For small tasks, follow the sequence; as complexity grows, divide by responsibility
For small tasks, following the sequence was easier; as complexity grew, dividing by responsibility worked better

Procedural programming designs the sequence; object-oriented programming designs responsibility.

This Is How It Comes Up in Interviews

Q. What is the biggest difference between procedural and object-oriented programming? A. The relationship between data and functionality. Procedural programming separates data and functions and flows around sequence, while object-oriented programming bundles them into objects and manages them by responsibility. This makes it better suited to maintenance and collaboration as systems grow.

Q. Why is encapsulation important? A. It prevents external code from changing data directly, reducing unexpected modifications. Because access is limited to defined methods, bugs are easier to trace, and changing the internal implementation has less impact on external code.


Even if the terminology sounds grand, the core question is simply: “How should we handle data?”

Practice grouping small pieces of code into objects, and it will soon click. Try refactoring one piece of your own code with what you learned today.