Lecture 2 - OOP Introduction Part 2.Pptx
Lecture 2 - OOP Introduction Part 2.Pptx
1-1
Lecture 2
Lecture Overview
Chapter 2. Introduction to OOP Part 2
1-2
Information Hiding
3
Example – Information Hiding
Ali’s name is stored within his brain
We can’t access his name directly
Rather we can ask him to tell his name
=============================== =====
A phone stores several phone numbers
We can’t read the numbers directly from the SIM
card
Rather phone-set reads this information for us
4
Information Hiding Advantages
5
Encapsulation
❑ We don’t know
❑ How the data is stored
❑ How Ali translates this information
6
Example – Encapsulation
We don’t know
How the data is stored
How it is converted to human-readable characters
7
Encapsulation – Advantages
Low complexity
Better understanding
8
Object has an Interface
An object encapsulates data and behavior
So how objects interact with each other?
Each object provides an interface (operations)
Other objects communicate through this interface
Example – Interface of a Car
✔Steer Wheels
✔Accelerate
✔Change Gear
✔Apply Brakes
✔Turn Lights On/Off
9
Example – Interface of a Phone
✔ Input Number
✔ Place Call
✔ Disconnect Call
✔ Add number to address book
✔ Remove number
✔ Update number
Implementation
Functionality
Mechanism to change gear
Example – Implementation of Address Book in a
Phone
Data Structure
SIM card
Functionality
Read/write circuitry
Separation of Interface & Implementation