0% found this document useful (0 votes)
2 views

Lecture 2 - OOP Introduction Part 2.Pptx

The document provides an overview of Object Oriented Programming (OOP) concepts, focusing on information hiding, encapsulation, and the separation of interface and implementation. It explains how data is stored within objects and manipulated through defined interfaces, using examples like a person's brain and a phone's functionality. The advantages of these principles include simplicity, low complexity, and reduced risk of errors from direct access to object data.

Uploaded by

zainattiq694
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 2 - OOP Introduction Part 2.Pptx

The document provides an overview of Object Oriented Programming (OOP) concepts, focusing on information hiding, encapsulation, and the separation of interface and implementation. It explains how data is stored within objects and manipulated through defined interfaces, using examples like a person's brain and a phone's functionality. The advantages of these principles include simplicity, low complexity, and reduced risk of errors from direct access to object data.

Uploaded by

zainattiq694
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Object Oriented Programming

Department of Computer Science

Lecturer: Abdul Rehman

Reference Book: Java How to Program By Deitel and


Deitel – 10th Edition

1-1
Lecture 2

Lecture Overview
Chapter 2. Introduction to OOP Part 2

1-2
Information Hiding

❑ Information is stored within the object

❑ It is hidden from the outside world

❑ It can only be manipulated by the object itself

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

Simplifies the model by hiding implementation details

It is a barrier against change propagation

5
Encapsulation

❑ Data and behavior are tightly coupled inside an object

❑ Both the information structure and implementation


details of its operations are hidden from the outer world
Example – Encapsulation..
❑ Ali stores his personal information and knows how to
translate it to the desired language

❑ We don’t know
❑ How the data is stored
❑ How Ali translates this information
6
Example – Encapsulation

A Phone stores phone numbers in digital format and knows


how to convert it into human-readable characters

We don’t know
How the data is stored
How it is converted to human-readable characters

7
Encapsulation – Advantages

Simplicity and clarity

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

❑ Provides services offered by the object interface


❑ This includes
✔Data structures to hold object state
✔Functionality that provides required services
Example – Implementation of Gear Box
Data Structure
Mechanical structure of gear box

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

✔ Change in implementation does not effect object interface


✔ Achieved via principles of information hiding and
encapsulation.
Example – Separation of Interface & Implementation
❑ A driver can drive a car independent of engine type
(petrol, diesel)
❑ Because interface does not change with the
implementation.
❑ A driver can apply brakes independent of brakes type
(simple, disk).
❑ Again, reason is the same interface
Advantages of Separation

✔ Users need not to worry about a change until the


interface is same.
✔ Low Complexity
✔ Direct access to information structure of an object can
produce errors
15

You might also like