EN አማ
Back to TTLM Library
OOP (Object Oriented Programming)

OOP (Object Oriented Programming)

Sintayehu  |  June 24, 2026 at 9:51 PM  |  26 days ago  |  31 views

Lecture Notes: Introduction to Object-Oriented Programming (OOP)

Course: Introduction to Computer Science
Topic: Object-Oriented Programming
Target Audience: Beginners with basic knowledge of variables, loops, and functions.

1. Why OOP? The Problem with Procedural Programming

Imagine you are writing a program for a university.

You need to manage Students, Professors, and Courses.

Each student has a name, an ID, a list of grades, and a GPA.

Each professor has a name, an ID, a department, and a salary.

In traditional Procedural Programming, you would use variables and functions:

student_names = []

student_ids = []

calculate_gpa(student_id, grades)

give_raise(professor_id, amount)

The Problems:

Scattered Data: Your data (names, IDs) is stored separately from the logic (functions).

Complexity: As the program grows, it becomes a giant web of functions and data that is hard to manage.

Code Duplication: If you have two different types of "People" (Student and Professor), you have to manage their data separately.

Real-world mapping: The code doesn't look like the real world. You have functions floating around, not "things" doing actions.

OOP solves this by bundling data and behavior together into "Objects."

2. What is Object-Oriented Programming (OOP)?

OOP is a programming paradigm (a style of coding) that organizes software design around objects rather than functions and logic.

An object is a "thing" that has two main characteristics:

Attributes (Data/Properties): What the object is or has (e.g., a car has a color, a dog has a name).

Methods (Behavior/Functions): What the object can do (e.g., a car can drive, a dog can bark).

Analogy:
Think of a Blueprint (like an architect's plan for a house) and the House itself.

Class: The Blueprint. It describes what the house looks like (color, rooms) and how it works (plumbing, electricity).

Object: The actual House built from that blueprint. You can build many houses from the same blueprint. Each house has its own paint color (attributes) and its own doors that open (methods).

3. The Four Main Pillars of OOP

There are 4 core concepts that define OOP.

Pillar 1: Encapsulation (Binding Data and Methods)

Definition: Bundling the data (attributes) and the methods (functions) that operate on that data into a single unit (a class). It also involves hiding the internal state of an object from the outside world and only exposing what is necessary.

Why? This prevents accidental modification of data and makes the code more secure.

Previous | Next