2 - Object Oriented Programming (OOP) - CS304 Power Point Slides Lecture 02
2 - Object Oriented Programming (OOP) - CS304 Power Point Slides Lecture 02
(OOP)
Lecture No. 2
Lecture Outlines
► 1. Information Hiding
► 2. Encapsulation
► 3. Interface
► 4. Implementation
► 5. Separation of Interface & Implementation
► 6. Messages
Information Hiding
► Information hiding is one of the most important principles
of OOP inspired from real life which says that all
information should not be accessible to all persons.
► Private information should only be accessible to its owner.
► In object oriented programming approach we have
objects with their attributes and behaviors that are hidden
from other classes, so we can say that object oriented
► programming follows the principle of information hiding.
Examples – Information Hiding
► Ali’s name and other personal information is stored in his
brain we can’t access this information directly. For getting
this information we need to ask Ali about it and it will be
up to Ali how much details he would like to share with us.
► An email server may have account information of millions
of people but it will share only our account information
with us if we request it to send anyone else accounts
information our request will be refused.
► 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
Information Hiding
Advantages
► Simplifies
the model by hiding
implementation details
► We don’t know
How the data is stored
How Ali translates this information
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
Encapsulation – Advantages
► Low complexity
► Better understanding
Object has an 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
► Because
interface does not change with the
implementation
Example – Separation of
Interface & Implementation