Introduction to Object-Oriented Programming
Object-Oriented Programming, or OOP, is a way to organize a program. It keeps the data and actions related to one thing together inside an object.
Start With a Simple Program
Every program has data and actions. A music app stores song details and plays songs. A shopping app stores product details and adds products to a cart.
In a very small program, we can keep this data in variables and write a few functions. That works well at first.
What Happens When the Program Grows?
Now imagine that the shopping app has thousands of lines of code. It has customer names, product prices, cart items, payments, and orders. It also has many functions that use this data.
If everything is kept together, it becomes difficult to know which function should use which data. A small change in one place may accidentally affect another part of the program.
- Related data can become scattered across many files.
- Any function may change data in the wrong way.
- The same logic may be written again in several places.
- Finding and fixing bugs becomes harder.
How OOP Helps
OOP divides a large program into smaller, meaningful objects. Each object keeps the information it needs and provides actions that work with that information.
For example, a Cart object keeps cart items and provides actions such as addItem, removeItem, and calculateTotal. Other parts of the program ask the Cart object to do this work.
- Related data and actions stay in one place.
- Each object gets a clear responsibility.
- The rest of the program uses the object through its allowed actions.
- A change is easier to understand because it often stays inside one object.
What Is an Object?
An object represents one thing inside a program. That thing can be a real item, such as a Car, or an idea used by the software, such as an Order or Payment.
An object represents a responsibility and may contain related data, behaviour, or both.
- Data tells us what the object knows. A Contact knows its name and phone number.
- Actions tell us what the object can do. A Contact can be called, edited, or deleted.
A Familiar Example: Phone Contacts
Open the Contacts app on a phone. Every saved contact keeps related data such as a name, phone number, and email address. The application uses that contact for actions such as call, message, edit, and delete.
We can think of every saved contact as an object. Vivek's contact and Anu's contact store different values. The application can use those values to start a call or message and can ask the Contact object to update its own details.
A Simple Analogy
Imagine a school office with one huge table. Student records, teacher records, fee receipts, and exam papers are all mixed together. Anyone can pick up and change anything. The office may work when the school is small, but it becomes confusing as the school grows.
Now give each department its own records and duties. The accounts department manages fees, the exam department manages marks, and the admissions department manages new students. They can still work together, but each department is responsible for its own information.
OOP organizes a program in a similar way. Objects keep related information and work together through clear actions.
Before OOP and With OOP
OOP is one way to organize code. It does not add new abilities to the computer; it gives developers a clearer structure for building larger programs.
The Same Cart, Organized in Two Ways
The following two approaches can produce the same result. OOP changes how the code is grouped, not what the computer is able to do.
The Basic Words You Need
For now, remember only two words. The next topic explains both in detail.
- Class: A definition that describes what a type of object should contain and do.
- Object: One actual item created from that class, with its own data.
Do We Always Need OOP?
No. A small calculation, a short script, or a simple sequence of steps may be clearer with normal variables and functions.
OOP is most useful when a program has many related things, rules, and interactions. Shopping systems, banking applications, games, and large user interfaces are common examples.
Procedural and functional programs can also be organized well. OOP is a useful design approach, not an automatic guarantee of clean code. Poorly designed classes can still make a program difficult to understand.
The basic OOP thinking flow
- 01Look at the problem and find the important things. In a shopping app, these may be Product, Cart, Customer, and Order.
- 02For each thing, decide what information it must remember.
- 03Decide what actions belong to that thing.
- 04Keep that data and those actions together in one class.
- 05Create objects from the classes and let the objects work together.
Example
Adding a product to a shopping cart
The Product object keeps the product name and price. The Cart object keeps the selected items and knows how to calculate their total. When the user adds a product, the app asks the Cart object to add that Product. Each object handles a clear part of the task.
A common mistake
OOP is not simply writing code with classes. The main goal is to give each object related data, useful actions, and a clear responsibility.

