OBJECT-ORIENTED PROGRAMMING (OOP) — SIMPLE NOTE
This note explains OOP in simple language.
You will learn:
- why good code is more than code that only works
- what procedural programming is
- what object-oriented programming is
- what a class is
- what an instance is
- what an interface is
1. Good code vs bad code
At first, it may seem that the difference is simple:
- good code works
- bad code does not work
But in real projects, that is not enough.
A modern product can have a very large codebase. So code must not only work, it must also be easy to support, improve, and grow.
Important qualities of good code are:
- reliability — the program should work stably
- scalability — the program should handle growth
- adaptability — the program should be easy to change
- cost efficiency — development and maintenance should not be too expensive
Diagram 1. Good code is more than “it works”
Good code
│
├─ works correctly
├─ is reliable
├─ is scalable
├─ is adaptable
└─ is cost-effective
A program that works today but is hard to change tomorrow is not really good code.
2. Why programming paradigms matter
To write better code, developers use programming paradigms.
A programming paradigm is a general way of organizing code.
In this topic, the two important paradigms are:
- procedural programming
- object-oriented programming (OOP)
Diagram 2. Two approaches
Programming paradigms
│
├─ Procedural programming
└─ Object-oriented programming
3. Procedural programming
Procedural programming is a style where a program is built as a set of functions that work with data.
The main ideas are:
- functions do the work
- variables store the data
- local variables belong only to one function
- global variables are available in the whole program
Diagram 3. Procedural programming idea
Data
↓
Functions process the data
↓
Result
In procedural programming, data and functions are often separate.
4. Procedural programming example
const baseSalary = 30000;
const overtime = 10;
const rate = 20;
const getWage = (baseSalary, overtime, rate) => {
return baseSalary + overtime * rate;
};
getWage(baseSalary, overtime, rate);
This is a procedural style because:
- the data is stored in separate variables
- the function is separate too
- the connection between them is logical, but not strongly grouped together
Diagram 4. Procedural example structure
baseSalary
overtime
rate
↓
getWage(...)
↓
result
The function needs outside values to work.
5. Strength of procedural programming
Procedural programming is:
- simple
- direct
- easy to understand for small tasks
It is good for simple programs.
6. Weakness of procedural programming
As a program becomes more complex, this style can become weaker because the connection between:
- data
- the functions that work with that data
becomes less clear.
Diagram 5. Problem in procedural programming
Data Function
baseSalary getWage()
overtime
rate
They work together,
but they are stored separately
In large programs, this can make the code harder to maintain.
7. Object-oriented programming (OOP)
Object-oriented programming, or OOP, is a style where programs are organized as a collection of objects.
An object represents a real or abstract thing, for example:
- a user
- a store
- a car
- an employee
Each object contains:
- data → properties
- behavior → methods
Diagram 6. OOP idea
Object
│
├─ properties (data)
└─ methods (actions)
In OOP, data and the functions that work with that data are grouped together.
8. OOP example
Let us rewrite the wage example in OOP style:
const employee = {
baseSalary: 30000,
overtime: 10,
rate: 20,
getWage() {
return this.baseSalary + this.overtime * this.rate;
},
};
employee.getWage();
Why this is OOP
Now:
- the data belongs to
employee - the method
getWage()also belongs toemployee - the object keeps related things together
Diagram 7. OOP example structure
employee
│
├─ baseSalary: 30000
├─ overtime: 10
├─ rate: 20
└─ getWage()
This is more organized than storing everything separately.
9. Why OOP is useful
OOP helps because it:
- structures code better
- makes development easier
- makes support easier
- helps build more complex programs
Diagram 8. Why OOP helps
OOP
↓
better structure
↓
easier maintenance
↓
better for complex programs
10. What is a class?
A class is a blueprint or template for creating objects. It describes:
- what data objects should have
- what actions objects should be able to perform
The source text explains this through a car example. Imagine designing a car before it is built. You decide:
- what parts it has
- how those parts work together
- what actions the car can perform
That design is like a class.
Diagram 9. Class = blueprint
Class
↓
template / blueprint
↓
used to create objects
A class is not one real object yet. It is the general model.
11. Car example for class
If we design a car class, we describe:
Properties
- engine
- wheels
- headlights
- fuel tank
Methods
- open the door
- start the engine
- increase speed
- decrease speed
Diagram 10. Car class
Car class
│
├─ properties
│ ├─ engine
│ ├─ wheels
│ ├─ headlights
│ └─ fuel tank
│
└─ methods
├─ openDoor()
├─ startEngine()
├─ speedUp()
└─ slowDown()
12. What is an instance?
An instance is a real object created from a class.
If the class is the blueprint of a car, then an instance is one real car made from that blueprint.
The class gives the structure.
The instance gives the real values.
Diagram 11. Class vs instance
Class
↓
blueprint of a car
Instance
↓
one real car created from that blueprint
The class is general. The instance is concrete.
13. Easy way to remember class and instance
Class = model
Instance = real object made from the model
Or:
Class = drawing
Instance = built object
14. Why instances are unique
Even if many objects are created from the same class, they are still different.
For example, cars from the same model can still have different:
- body numbers
- engine numbers
- colors
- interior design
Diagram 12. Same class, many unique objects
One class
↓
Car 1
Car 2
Car 3
Same structure
Different values
That is why classes are useful: one blueprint can create many real objects.
15. What is an interface?
An interface is the set of properties and methods of a class that are available for use when working with an instance.
In simple words:
The interface is what you can use.
The text compares this to a car dashboard.
When you sit in a car, you interact with:
- pedals
- steering wheel
- gear shift
- lights
- buttons
That is similar to using the interface of a class.
Diagram 13. Interface idea
Class
↓
available controls
↓
interface
The interface shows what actions are possible.
16. Car interface example
In the car example, the interface allows actions like:
- increase speed
- brake
- turn
- change gears
- turn on the lights
Diagram 14. Car dashboard = interface
Dashboard controls
│
├─ brake
├─ speed up
├─ turn
├─ change gear
└─ switch lights on
The driver does not need to know every inner detail of the engine.
The driver just uses the interface.
17. Good interface balance
The source text explains that when designing an interface, you need balance between:
- simplicity
- flexibility
If the interface is too simple:
- it is easy to use
- but it may be too limited
If the interface is too flexible:
- it can do many things
- but it may become too hard to use and easier to misuse
Diagram 15. Interface balance
Too simple
↓
easy to use
but limited
Too complex
↓
powerful
but harder to use
A good interface should be powerful enough, but still easy to understand.
18. Procedural programming vs OOP
Now we can compare them clearly.
Procedural programming
- data and functions are usually separate
- simple for small tasks
- can become harder to maintain in large programs
OOP
- data and methods are grouped in objects
- better structure
- better for larger and more complex programs
Diagram 16. Procedural vs OOP
Procedural
↓
separate data + separate functions
OOP
↓
object = data + methods together
19. Easy memory rules
Procedural = functions work on separate data
OOP = objects keep data and behavior together
Class = blueprint
Instance = real object
Interface = available controls
20. Quick summary
- Good code is not only code that works, but also code that is reliable, scalable, adaptable, and cost-effective.
- Procedural programming organizes code as functions and variables.
- OOP organizes code as objects with properties and methods.
- A class is a blueprint for creating objects.
- An instance is a real object created from a class.
- An interface is the set of available properties and methods used to work with an object.
21. Final conclusion
OOP is important because it helps organize code in a way that is easier to build, understand, and maintain.
If you understand these four ideas:
Object = data + methods
Class = blueprint
Instance = real object
Interface = available controls
then you already understand the basic foundation of object-oriented programming.