Introduction to OOP, Class as an ADT & Procedural vs Object-Oriented Programming
1. Topic Introduction
Before OOP became the industry standard, large programs written in procedural languages (like C) often turned into fragile tangled webs of global variables and functions. Object-Oriented Programming (OOP) restructures software around interacting real-world objects that protect their own data—making massive systems understandable, modular, and reusable.
In Procedural Programming (like C), imagine placing all cash in one open table in the middle of a room (global data) while dozens of workers (functions) reach in and modify it directly. If one worker alters a rule, five other functions break! In Object-Oriented Programming, every department (Account, LibraryMember, Book) locks its own cash inside a safe (private attributes) and provides a service window (public methods) like deposit() or issueBook(). Other objects must politely request service via those windows!
3. Essential Exam Definitions
4. Detailed Technical Explanation & Syntax
1. Problem Decomposition Using Objects (Library System Example)
In a Library Automation System, rather than writing isolated issue_book() and return_book() C functions reading global arrays, OOP identifies tangible real-world entities (LibraryMember, Book, IssueRegister) and conceptual entities (Scheduler, NotificationService).
For example, a LibraryMember object bundles private attributes (memberId, name, address, booksIssued) with public operations (issueBook(), returnBook(), findBooksOverdue()). Breaking a huge problem into cohesive objects makes design and maintenance intuitive.
2. Why Every Class is an ADT (Abstract Data Type)
In your lecture notes, an important conceptual question is: 'Is a class an ADT?' Let us prove it cleanly in two steps:
- Abstract Data: Data contained inside an object is accessible ONLY through its methods; callers have zero knowledge of whether internal storage uses an array, stack, or linked list.
- Data Type: A data type defines values + operations and can be instantiated (
int i;instantiatesint). Because a class can be instantiated into objects (LibraryMember m1 = new LibraryMember();), a class IS a data type. - Conclusion: Every Class is an ADT! (However, the converse is not always true—an ADT in non-OOP languages like C
struct+ functions is an ADT without being a class).
5. Working Principle: How Objects Collaborate Without Corrupting Each Other
- Object A needs information from Object B (e.g.,
IssueRegisterneeds to know ifLibraryMembercan borrow another book). - Object A does NOT directly read or edit Object B's private
booksIssuedfield. - Instead, Object A sends a message (invokes
member.canBorrow()) — Object B checks its own rules and responds safely.
6. Examination-Ready Diagrams
OOP Concepts (Four Pillars)
Visual overview of the four core pillars of Object-Oriented Programming surrounding Class & Object decomposition.
- Abstraction: Shows essential features while hiding internal implementation complexity.
- Encapsulation: Binds data + methods together inside a class and protects data via private access.
- Inheritance: Allows a subclass to acquire properties and behaviors of a superclass (
extends). - Polymorphism: One interface, multiple forms — compile-time overloading and runtime overriding.
- Encapsulation wraps private fields and public methods into a safe unit (class).
- Abstraction exposes only relevant contracts (abstract classes / interfaces).
- Inheritance builds specialized subclasses reusing common parent attributes.
- Polymorphism lets the same method call behave differently depending on arguments or runtime object.
- Draw a central hub labeled 'Object-Oriented Programming (Class & Object)' connected to 4 pillars: Encapsulation, Abstraction, Inheritance, Polymorphism.
- Inside each pillar box, add a 3–4 word exam keyword: e.g., 'Data + Methods, private', 'Hide complexity', 'IS-A reuse (extends)', 'Many forms (Overload/Override)'.
7. Complete Java Code Examples & Tracing
| 1 | class LibraryMember { |
| 2 | // Abstracted internal data (hidden from external objects) |
| 3 | private int memberId; |
| 4 | private String name; |
| 5 | private int booksIssued; |
| 6 | private static final int MAX_BOOKS = 3; |
| 7 | |
| 8 | public LibraryMember(int memberId, String name) { |
| 9 | this.memberId = memberId; |
| 10 | this.name = name; |
| 11 | this.booksIssued = 0; |
| 12 | } |
| 13 | |
| 14 | // Well-defined public operations (ADT interface) |
| 15 | public boolean issueBook(String bookTitle) { |
| 16 | if (booksIssued < MAX_BOOKS) { |
| 17 | booksIssued++; |
| 18 | System.out.println(name + " (#" + memberId + ") borrowed: " + bookTitle); |
| 19 | return true; |
| 20 | } |
| 21 | System.out.println("Limit reached for " + name + "! Cannot issue: " + bookTitle); |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | public void returnBook(String bookTitle) { |
| 26 | if (booksIssued > 0) { |
| 27 | booksIssued--; |
| 28 | System.out.println(name + " returned: " + bookTitle); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public int getBooksOutstanding() { |
| 33 | return booksIssued; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public class LibrarySystemDemo { |
| 38 | public static void main(String[] args) { |
| 39 | LibraryMember member = new LibraryMember(104, "Meera"); |
| 40 | member.issueBook("Java Complete Reference"); |
| 41 | member.issueBook("Clean Code"); |
| 42 | member.returnBook("Clean Code"); |
| 43 | System.out.println("Books currently held: " + member.getBooksOutstanding()); |
| 44 | } |
| 45 | } |
Meera (#104) borrowed: Java Complete Reference Meera (#104) borrowed: Clean Code Meera returned: Clean Code Books currently held: 1
classprivatepublicnew- Leaving fields public and letting external code mutate
member.booksIssued = 99;directly. - Confusing a Class (blueprint) with an Object (runtime instance).
Comparison Tables
| Comparison Point | Procedural Programming (e.g., C) | Object-Oriented Programming (e.g., Java) |
|---|---|---|
| Core Focus | Algorithms / Functions (procedures) | Objects bundling data + methods |
| Approach | Top-down decomposition | Bottom-up decomposition |
| Data Security | Low; data often shared globally across functions | High; private data hidden via encapsulation |
| Code Reuse | Limited (function copy or libraries) | High via Inheritance, Polymorphism & Composition |
| Coupling & Maintenance | Tight coupling; changing global data breaks functions | Weak coupling; easy to extend large systems |
| Real-World Mapping | Harder to map entities directly | Maps directly to real-world & conceptual entities |
Advantages
- Code and design reuse via class libraries and inheritance.
- Increased productivity, easier testing, and simplified maintenance.
- Better management of large problem complexity via intuitive abstraction and weak coupling.
Limitations / Disadvantages
- Slight runtime overhead (extra indirection, dynamic dispatch, object allocation) making OOP marginally slower than raw procedural C in tight low-level loops.
- Data centralized in a procedural program becomes distributed across multiple interacting objects, requiring careful architectural design.
Real-World Applications
- Banking systems, university ERP portals, GUI frameworks (Swing), and enterprise backend platforms.
Important KTU Exam Points
- Expect a direct 3-mark or 6-mark comparison table between Procedural Programming and OOP.
- Know the exact proof for 'Is a class an ADT?': Abstract Data (hidden behind methods) + Data Type (instantiable) = ADT.
- Mention BOTH advantages AND disadvantages of OOD when asked in 6/9-mark theory answers!
Memory Techniques & Revision
- Proc = 'Top-Down, Functions First, Open Data'; OOP = 'Bottom-Up, Objects First, Hidden Data'.
Common Pitfalls to Avoid
- Saying OOP is always faster at CPU execution than C — OOP trades tiny runtime overhead for huge gains in safety, maintainability, and scalability.
KTU-Style Questions & Exam-Ready Answers
Structured specifically for KTU Part A (3-mark) and Part B (6/9-mark) evaluation rubrics.
Introduction: Procedural Programming and Object-Oriented Programming represent two fundamental paradigms for structuring software systems.
- Focus: Procedural programming prioritizes functions/procedures acting on separate data; OOP models self-contained objects binding data and methods together.
- Design Direction: Procedural uses top-down design; OOP uses bottom-up design.
- Data Hiding: Procedural exposes data globally (less secure); OOP protects data using access modifiers (
private,protected) and encapsulation. - Extensibility & Reuse: OOP enables inheritance and polymorphism (
one interface, multiple methods), yielding weak coupling and easier maintenance for large applications.
Quick Understanding Check
1. Which statement accurately describes the relationship between Class and ADT?