Unit 2 · Introduction to Object-Oriented Programming
2.2Procedural vs Object-Oriented Programming
| Feature | Procedural | Object-oriented |
|---|
| Main unit | Function | Object (created from a class) |
| Focus | What steps must be done | Which things take part and what they do |
| Data and functions | Separate | Bundled together |
| Data security | Weak: data is often global | Strong: data can be hidden (encapsulation) |
| Reuse | Copy or call functions | Inheritance and composition |
| Modelling real life | Harder | Natural: objects mirror real things |
| Maintenance of large programs | Becomes difficult | Easier, because changes stay inside classes |
| Typical use | Small scripts, system utilities | Large applications, GUIs, games, enterprise systems |
Reading the comparison
- Main unit: a procedural program is a list of functions; an OOP program is a set of objects created from classes.
- Focus: procedural design asks "what steps must happen?"; OOP design asks "which things take part, and what is each responsible for?"
- Data security: in OOP, data can be made
private, so only the object's own methods can change it. Global data in a procedural program can be changed by any function. - Reuse: OOP adds two powerful ways to reuse code. Inheritance lets a new class extend an existing one, and composition lets a class be built from other objects (see Unit 4).
- Maintenance: in OOP a change usually stays inside one class. As long as the class's public methods stay the same, the rest of the program does not notice.
In this section