12.2 Programming Paradigms: Procedural, Object-Oriented, and Others
Key Takeaways
- Procedural programming organizes a program as a sequence of procedures that operate on data passed to them or stored in variables; key terms include procedure, parameter, return value, local and global variable, and top-down design.
- Object-oriented programming organizes a program around objects that bundle state (instance variables) with behavior (methods); key terms include class, object, constructor, encapsulation, inheritance, and polymorphism.
- Functional programming emphasizes pure functions without side effects, immutable data, and passing functions as values.
- Declarative languages such as SQL describe what result is wanted rather than the steps to compute it.
- Many languages, including Python, JavaScript, and C++, are multi-paradigm, so the paradigm describes how code is organized, not just which language is used.
What this competency asks
ETS asks you to be familiar with different programming paradigms:
- Identify the terminology of procedural programming.
- Identify the terminology of object-oriented programming.
- Compare programming paradigms.
The discussion question asks you to describe differences between paradigms such as procedural and object-oriented.
What a paradigm is
A programming paradigm is a fundamental approach to structuring a program: how data and behavior are organized and how computation proceeds. A language may be designed around one paradigm, as Java is around objects, or support several. Python can be written procedurally, in an object-oriented way, or in a functional style.
Procedural programming
Procedural (imperative) programming describes computation as a sequence of statements that change the program's state (its variables), organized into procedures.
| Term | Meaning |
|---|---|
| Procedure / function / subroutine | A named block of statements that performs a task |
| Parameter and argument | The inputs to a procedure and the values passed in |
| Return value | The result a procedure sends back |
| Local and global variables | Scope of data (Section 9.1) |
| Sequence, selection, iteration | Control structures |
| Top-down design / stepwise refinement | Breaking the task into procedures, then refining each |
Examples: C, Pascal, and early BASIC; also procedural-style code in Python, JavaScript, and the ETS pseudocode.
Strengths: simple to learn, direct control of the steps, and efficient for straightforward tasks and scripts.
Weaknesses: in large programs, data and the procedures that change it are separate, so many procedures may touch the same data, and a change to the data's structure can ripple through the program.
Object-oriented programming (OOP)
OOP organizes a program around objects, which bundle data and the operations on that data.
| Term | Meaning |
|---|---|
| Class | A blueprint that defines the data and methods of a type of object |
| Object / instance | A specific thing created from a class, often with new |
| Instance variable (field, attribute) | Data stored in each object |
| Method | A procedure defined in a class that operates on an object |
| Constructor | A special method that initializes a new object |
| Encapsulation | Keeping data private and exposing it only through public methods |
| Inheritance | A subclass (extends) reuses and extends a superclass |
| Polymorphism | The same method call behaves differently depending on the object's actual class |
| Abstraction | Exposing what an object does while hiding how |
Examples: Java, C#, C++, Python, and Ruby. Sections 12.3 and 12.4 cover OOP in detail.
Strengths: models real-world entities naturally; encapsulation protects data; inheritance and polymorphism support reuse and extension; and it scales well to large team projects.
Weaknesses: more design effort and code up front, and deep inheritance hierarchies can become rigid.
The same task in two paradigms
Procedural: the data (a balance) and the procedure are separate. The procedure receives the data.
double deposit ( double balance, double amount )
if ( amount > 0 )
return balance + amount
end if
return balance
end deposit
Object-oriented: the data and its operations live together in a class.
class Account
private double balance
public void deposit ( double amount )
if ( amount > 0 )
balance ← balance + amount
end if
end deposit
end class Account
In the OOP version, only Account's methods can change balance, so the rule "deposits must be positive" is enforced in one place.
Other paradigms to recognize
| Paradigm | Core idea | Key terms | Examples |
|---|---|---|---|
| Functional | Compute by applying and combining functions; avoid changing state | Pure function (no side effects), immutability, higher-order function (a function that takes or returns a function), recursion, map / filter / reduce | Haskell, Lisp, Scheme; functional features in Python and JavaScript |
| Declarative | Describe what result you want, not how to get it | Query, rule, constraint | SQL (SELECT … WHERE …), HTML, spreadsheet formulas |
| Logic (a kind of declarative) | State facts and rules; the system infers answers | Fact, rule, query | Prolog |
| Event-driven | Code runs in response to events | Event, handler, callback, event loop | JavaScript interfaces, Scratch, mobile apps (Section 11.1) |
Comparing paradigms
| Question | Procedural | Object-oriented | Functional |
|---|---|---|---|
| How is code organized? | Procedures | Classes and objects | Functions |
| Where does data live? | Variables and data structures passed to procedures | Inside objects, encapsulated | Immutable values passed between functions |
| How is state changed? | By assignment statements | By methods that change an object's fields | Avoided; new values are created instead |
| Main reuse mechanism | Calling procedures | Inheritance, composition, polymorphism | Composing and passing functions |
| Well suited to | Scripts, algorithms, small programs | Large systems of interacting entities: games, interfaces, simulations | Data transformation, concurrency (no shared state to corrupt) |
No paradigm is best for everything. Choose based on the problem, the team, and the language. A program can also mix styles, for example an OOP application whose methods use procedural loops and functional list operations.
Which set of terms belongs primarily to object-oriented programming?
A program is written as a series of procedures, such as readScores, computeAverage, and printReport, that are called in order from a main routine and pass data to one another through parameters and return values. Which paradigm does this best describe?
A team is building a simulation of a zoo with many kinds of animals. Each kind shares some behaviors (eat, sleep) but has its own version of others (makeSound, move). Which paradigm offers the most natural fit, and why?
The statement SELECT name FROM students WHERE grade = 10 retrieves a list of names without specifying any loop or search algorithm. Which paradigm does it illustrate?