SlideShare a Scribd company logo
Lecture-2
Instructor Name:
Object Oriented Programming
Today’s Lecture
 Information Hiding
 Encapsulation
 Interface
 Implementation
 Abstraction
2
Information Hiding
Introduction
 Information hiding is one the most important principle of OOP which says the
private information should only be accessible to the owner.
 Information Hiding means “Showing only those details to the outside world
which are necessary for the outside world and hiding all other details from the
outside world.”
 Information is stored within the Object
 Information within the object is not accessible to outside world
 Information can only be manipulated by the object
3
Information Hiding
Introduction
 Information hiding: a module is characterized by the information it hides from
other modules, which are called its clients. The hidden information remains a
secret to the client modules. (Ghezzi et al)
 The purpose of Information hiding is to make inaccessible certain details that
should not affect other parts of a system. (Ross et al)
 Information hiding is the principle that users of a software component (such as a
class) need to know only the essential details of how to initialize and access the
component, and do not need to know the details of the implementation. (Budd)
4
Information Hiding
Information Hiding – Real Life Examples
 A Person’s (Say Ali) name other information is stored in this brain and we can not
access it directly
 An Email server has millions of email address but it shares only our account
information with us
 A phone SIM card may store several phone numbers but we can not read numbers
directly rather a phone set (a person’s own) will read this information for us
5
Information Hiding
Information Hiding in OOP’s Perspective
 In OOP an Object have state and behaviors that is hidden from outside world. So
in OOP perspective information hiding is
“Hiding object detail (state & behavior) from the users”
 Term “user” defined here means an “Object” of another class that is calling
functions of this class using or it may be another program in which we are using
this class.
6
Information Hiding
Advantages of Information Hiding
 Simplifies Object Oriented Model
In OOP Model we only have object and their interaction
 Barrier against change propagation
Any change in the functionality doesn’t effect the OOP model
7
Information Hiding
Achieving Information Hiding
 Information hiding can be achieved using
1. Encapsulation
2. Abstraction
8
Encapsulation
Introduction
9
Encapsulation
What is Encapsulation?
 Encapsulation means “All the characteristics of an object are hidden in the
object itself”.
 The wrapping up of data and function into a single unit is known as
encapsulation.
 Encapsulation hides the implementation details
 Encapsulation and information hiding are the same concepts so they may be
used as synonyms.
10
Encapsulation
Encapsulation and Object
 Data and Behaviour are tightly coupled inside an object
 Information structure and implementation details of its operations are hidden
from outside world.
11
Encapsulation
Encapsulation Example
 A Person (Say Ali) stores his personal information in itself and its behaviour is
also implemented in it. (Ali is an object of person)
 Now its up to Object Ali whether he wants to share this information with
outside world or not.
 Attributes and Behaviour of Ali are encapsulated in itself. 12
Encapsulation
Encapsulation Example
 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
13
Encapsulation
Advantages of Encapsulation
 Followings are the advantages of Encapsulation
1. Simplicity and Clarity
2. Low Complexity
3. Better Understanding
4. Ensure Structural Changes remain Local
5. Encapsulation Allows adding some logic when accessing client’s
data
For Example validation on modifying a property
14
Interface
Object and Interface
 Every Object has an Interface.
 Interface is set of functions of an object that he wants to expose to other
objects.
 An object encapsulates data and behaviour. So how will an object interact
with other objects?
 Objects communicate through this interface.
15
What would be the interface of a Phone?
Implementation
Object and Implementation
 The behaviour of object requires implementation.
 The actual implementation (coding) of the behaviour in any object oriented
language is called implementation.
 Implementation has two parts
1. Internal Data Structures to hold an object state that will be hidden from us
2. Functionality in the form of member functions to provide required
behaviour
 Example – Implementation of Gear Box
Data Structure
– Mechanical structure of gear box
Functionality
– Mechanism to change gear 16
Implementation
Object and Implementation
 What would be the implementation of an Address Book in a Phone
• Data Structure
– SIM card
• Functionality
– Read/write circuitry
17
Interface & Implementation
Separation of Interface & Implementation
 Only Interface of object is shown and implementation detail is hidden.
 Separating implementation detail from interface is very beneficial as Interface
becomes independent of implementation detail
Real Life Example of Separation of Interface & Implementation
 Driver has a standard interface to drive a car and using that interface he can
drive car of any model or any engine type
18
Messages
What is a message in OOP?
 A message is a request for an object to perform one of its operations (methods)
 All Communication between objects is done via messages
 The number and kind of messages that can be sent to an object depends upon
its interface
 The object to which message is addressed (yourBicycle)
 The name of the method to perform (changeGear)
 Any parameter needed by the method (lowerGear)
19
Messages
What is a message in OOP?
20
SHOULD WE INCLUDE THIS SLIDE ?
Abstraction
What is Abstraction?
 Abstraction means ignoring irrelevant features, properties, or functions and
emphasizing the relevant one
 …relevant to the given project (with an eye to future reuse in similar projects)
Abstraction = managing complexities
21
Abstraction
What is Abstraction?
 Abstraction is something we do everyday
 Looking at an object , we see those things about it that have
meanings to us.
 We abstract the properties of the object, and keep only what we
need.
 Abstraction allows us to represent a complex reality in terms of
simplified model
 Abstraction highlights the properties of an entity that we are most
interested in and hides the other 22
Abstraction
Abstraction Example
“Ali is PHD student and teaches BS students”
 Here Object Ali has two perspective one is student perspective and
other is teacher perspective.
Attributes
Student Perspective Teacher Perspective
Name Employee ID
Student Roll No Designation
Year of Study Salary
CGPA Age
 Age is common attribute in both perspectives
23
Abstraction
Abstraction Example
“Ali is PHD student and teaches BS students”
 Here Object Ali has different behaviors in student perspective and
teacher perspective.
Behavior
Student Perspective Teacher Perspective
Study Deliver Lecture
GiveExam TakeExam
PlaySports DevelopExam
24
Abstraction
Abstraction Example
“A cat can be viewed with different perspectives”
 Here Object Cat has different perspective on Ordinary perspective and
Surgeon perspective.
Ordinary Perspective Surgeon’s Perspective
A pet animal with A being with
Four Legs A Skeleton
A Tail Heart
Two Ears Kidney
Sharp Teeth Stomach
25
Abstraction
Abstraction Example
Driver’s View Engineer’s View
26
Abstraction
Abstraction Advantage
 Abstraction has following advantages
 Simplifies the model by hiding irrelevant details
 Abstraction provides the freedom to defer implementation
decisions by avoiding commitment to details.
27
28

More Related Content

PDF
Class and Objects in Java
PPT
Class and object in C++
PDF
Java conditional statements
PPTX
Python OOPs
PPTX
Data types in c++
PPTX
Constructor in java
PDF
Chapter2 Encapsulation (Java)
PPT
Object-oriented concepts
Class and Objects in Java
Class and object in C++
Java conditional statements
Python OOPs
Data types in c++
Constructor in java
Chapter2 Encapsulation (Java)
Object-oriented concepts

What's hot (20)

PPT
Operator Overloading
PPTX
Java package
PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
PPTX
Object Oriented Programing JAVA presentaion
PPTX
Oops concept in c++ unit 3 -topic 4
PPTX
Characteristics of OOPS
PPTX
Inheritance in JAVA PPT
PPTX
Oop c++class(final).ppt
PPTX
Polymorphism in java
PDF
Oops concepts || Object Oriented Programming Concepts in Java
PDF
Object oriented approach in python programming
PPSX
INTRODUCTION TO C PROGRAMMING
PPTX
OOP Introduction with java programming language
PDF
Constructors and Destructors
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PDF
Abstraction
PPTX
System Programming Unit II
PPTX
Inheritance in java
PPTX
Java abstract class & abstract methods
Operator Overloading
Java package
[OOP - Lec 08] Encapsulation (Information Hiding)
Object Oriented Programing JAVA presentaion
Oops concept in c++ unit 3 -topic 4
Characteristics of OOPS
Inheritance in JAVA PPT
Oop c++class(final).ppt
Polymorphism in java
Oops concepts || Object Oriented Programming Concepts in Java
Object oriented approach in python programming
INTRODUCTION TO C PROGRAMMING
OOP Introduction with java programming language
Constructors and Destructors
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Abstraction
System Programming Unit II
Inheritance in java
Java abstract class & abstract methods
Ad

Viewers also liked (10)

DOCX
PeterOviroh CV CURRENT
PPTX
Evaluation for mediastudies my project interrogation
PDF
Som la teva millor alumna i punt.
PDF
Som la teva millor alumna i punt
DOCX
Kort om units-systemet
PPTX
The Mushroom Cloud Effect or What Happens When Containers Fail? by Alois Mayr...
PPTX
VB Intro PPT
PDF
Dynamic Power Factor Correction in a Non Linear Environment
PPTX
Fungsi Matematika
PDF
I systems
PeterOviroh CV CURRENT
Evaluation for mediastudies my project interrogation
Som la teva millor alumna i punt.
Som la teva millor alumna i punt
Kort om units-systemet
The Mushroom Cloud Effect or What Happens When Containers Fail? by Alois Mayr...
VB Intro PPT
Dynamic Power Factor Correction in a Non Linear Environment
Fungsi Matematika
I systems
Ad

Similar to Lecture 2 (20)

PPT
Data encapsulation and information hiding
PPTX
gxhrehsrejhvytftfltyflytdtydtydky5dyrdtrdrdtrd
PPTX
Abstraction file
PPTX
Abstraction file
PPTX
Abstraction file
PPTX
Abstraction file
PPTX
Abstraction file
PPTX
Abstraction file
PPTX
Abstraction file
PPT
Object orientation technology
PPTX
Object oriented progrmming
PPTX
PDF
Object-Oriented Programming in Java (Module 1)
PPT
Chapter 02 The Object Model_Software E.ppt
PPTX
introduction of Object oriented programming
PPTX
Object Oriented Concept
PDF
L1-Introduction to OOPs concepts.pdf
DOCX
Benefits of encapsulation
PPTX
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
PPTX
1a-OO-Basics.pptx lạoanfanfanfjasnfjnfkaskfklas
Data encapsulation and information hiding
gxhrehsrejhvytftfltyflytdtydtydky5dyrdtrdrdtrd
Abstraction file
Abstraction file
Abstraction file
Abstraction file
Abstraction file
Abstraction file
Abstraction file
Object orientation technology
Object oriented progrmming
Object-Oriented Programming in Java (Module 1)
Chapter 02 The Object Model_Software E.ppt
introduction of Object oriented programming
Object Oriented Concept
L1-Introduction to OOPs concepts.pdf
Benefits of encapsulation
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
1a-OO-Basics.pptx lạoanfanfanfjasnfjnfkaskfklas

More from talha ijaz (16)

PPTX
Lecture 23-24.pptx
PPTX
Lecture 22
PPTX
Lecture 20-21
PPTX
Lecture 19
PPTX
Lecture 18
PPTX
Lecture 17
PPTX
Lecture 12
PPTX
Lecture 9
PPTX
Lecture 7
PPTX
Lecture 5
PPT
Visual perception
PPTX
Lecture 11
PPT
Introduction
PPTX
Lecture 4
PPTX
Lecture 3
PPTX
Lecture 1
Lecture 23-24.pptx
Lecture 22
Lecture 20-21
Lecture 19
Lecture 18
Lecture 17
Lecture 12
Lecture 9
Lecture 7
Lecture 5
Visual perception
Lecture 11
Introduction
Lecture 4
Lecture 3
Lecture 1

Recently uploaded (20)

PDF
Physics class 12thstep down transformer project.pdf
PDF
Caterpillar Cat 329D LN Excavator (Prefix EBM) Service Repair Manual Instant ...
PPTX
vsdfhlahsadfjkhasihdflakjsdfhlajdhlfkjahfdljkash
PDF
higher edu open stores 12.5.24 (1).pdf forreal
PDF
industrial engineering and safety system
PDF
Delivers.ai: 2020–2026 Autonomous Journey
PPTX
Materi Kuliah Umum Prof. Hsien Tsai Wu.pptx
PDF
Renesas R-Car_Cockpit_overview210214-Gen4.pdf
PDF
How much horsepower does a Volvo EC210Cl have.pdf
PDF
What are dimensions of the Volvo ECR235cl.pdf
PDF
Diagnose and Repair Transmission Sound Issues in Volkswagen Vehicles
PPTX
capstoneoooooooooooooooooooooooooooooooooo
DOCX
lp of food hygiene.docxvvvvvvvvvvvvvvvvvvvvvvv
PPTX
TOEFL ITP Grammar_ Clausessssssssssssssssss.pptx
PDF
Volvo ecr88 excavator specs Manual Download
PDF
Caterpillar CAT 312B L EXCAVATOR (2KW00001-UP) Operation and Maintenance Manu...
PPT
Kaizen for Beginners and how to implement Kaizen
PDF
computer system to create, modify, analyse or optimize an engineering design.
PDF
How much does a e145 excavator weight.pdf
PDF
Todays Technician Automotive Heating & Air Conditioning Classroom Manual and ...
Physics class 12thstep down transformer project.pdf
Caterpillar Cat 329D LN Excavator (Prefix EBM) Service Repair Manual Instant ...
vsdfhlahsadfjkhasihdflakjsdfhlajdhlfkjahfdljkash
higher edu open stores 12.5.24 (1).pdf forreal
industrial engineering and safety system
Delivers.ai: 2020–2026 Autonomous Journey
Materi Kuliah Umum Prof. Hsien Tsai Wu.pptx
Renesas R-Car_Cockpit_overview210214-Gen4.pdf
How much horsepower does a Volvo EC210Cl have.pdf
What are dimensions of the Volvo ECR235cl.pdf
Diagnose and Repair Transmission Sound Issues in Volkswagen Vehicles
capstoneoooooooooooooooooooooooooooooooooo
lp of food hygiene.docxvvvvvvvvvvvvvvvvvvvvvvv
TOEFL ITP Grammar_ Clausessssssssssssssssss.pptx
Volvo ecr88 excavator specs Manual Download
Caterpillar CAT 312B L EXCAVATOR (2KW00001-UP) Operation and Maintenance Manu...
Kaizen for Beginners and how to implement Kaizen
computer system to create, modify, analyse or optimize an engineering design.
How much does a e145 excavator weight.pdf
Todays Technician Automotive Heating & Air Conditioning Classroom Manual and ...

Lecture 2

  • 2. Today’s Lecture  Information Hiding  Encapsulation  Interface  Implementation  Abstraction 2
  • 3. Information Hiding Introduction  Information hiding is one the most important principle of OOP which says the private information should only be accessible to the owner.  Information Hiding means “Showing only those details to the outside world which are necessary for the outside world and hiding all other details from the outside world.”  Information is stored within the Object  Information within the object is not accessible to outside world  Information can only be manipulated by the object 3
  • 4. Information Hiding Introduction  Information hiding: a module is characterized by the information it hides from other modules, which are called its clients. The hidden information remains a secret to the client modules. (Ghezzi et al)  The purpose of Information hiding is to make inaccessible certain details that should not affect other parts of a system. (Ross et al)  Information hiding is the principle that users of a software component (such as a class) need to know only the essential details of how to initialize and access the component, and do not need to know the details of the implementation. (Budd) 4
  • 5. Information Hiding Information Hiding – Real Life Examples  A Person’s (Say Ali) name other information is stored in this brain and we can not access it directly  An Email server has millions of email address but it shares only our account information with us  A phone SIM card may store several phone numbers but we can not read numbers directly rather a phone set (a person’s own) will read this information for us 5
  • 6. Information Hiding Information Hiding in OOP’s Perspective  In OOP an Object have state and behaviors that is hidden from outside world. So in OOP perspective information hiding is “Hiding object detail (state & behavior) from the users”  Term “user” defined here means an “Object” of another class that is calling functions of this class using or it may be another program in which we are using this class. 6
  • 7. Information Hiding Advantages of Information Hiding  Simplifies Object Oriented Model In OOP Model we only have object and their interaction  Barrier against change propagation Any change in the functionality doesn’t effect the OOP model 7
  • 8. Information Hiding Achieving Information Hiding  Information hiding can be achieved using 1. Encapsulation 2. Abstraction 8
  • 10. Encapsulation What is Encapsulation?  Encapsulation means “All the characteristics of an object are hidden in the object itself”.  The wrapping up of data and function into a single unit is known as encapsulation.  Encapsulation hides the implementation details  Encapsulation and information hiding are the same concepts so they may be used as synonyms. 10
  • 11. Encapsulation Encapsulation and Object  Data and Behaviour are tightly coupled inside an object  Information structure and implementation details of its operations are hidden from outside world. 11
  • 12. Encapsulation Encapsulation Example  A Person (Say Ali) stores his personal information in itself and its behaviour is also implemented in it. (Ali is an object of person)  Now its up to Object Ali whether he wants to share this information with outside world or not.  Attributes and Behaviour of Ali are encapsulated in itself. 12
  • 13. Encapsulation Encapsulation Example  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 13
  • 14. Encapsulation Advantages of Encapsulation  Followings are the advantages of Encapsulation 1. Simplicity and Clarity 2. Low Complexity 3. Better Understanding 4. Ensure Structural Changes remain Local 5. Encapsulation Allows adding some logic when accessing client’s data For Example validation on modifying a property 14
  • 15. Interface Object and Interface  Every Object has an Interface.  Interface is set of functions of an object that he wants to expose to other objects.  An object encapsulates data and behaviour. So how will an object interact with other objects?  Objects communicate through this interface. 15 What would be the interface of a Phone?
  • 16. Implementation Object and Implementation  The behaviour of object requires implementation.  The actual implementation (coding) of the behaviour in any object oriented language is called implementation.  Implementation has two parts 1. Internal Data Structures to hold an object state that will be hidden from us 2. Functionality in the form of member functions to provide required behaviour  Example – Implementation of Gear Box Data Structure – Mechanical structure of gear box Functionality – Mechanism to change gear 16
  • 17. Implementation Object and Implementation  What would be the implementation of an Address Book in a Phone • Data Structure – SIM card • Functionality – Read/write circuitry 17
  • 18. Interface & Implementation Separation of Interface & Implementation  Only Interface of object is shown and implementation detail is hidden.  Separating implementation detail from interface is very beneficial as Interface becomes independent of implementation detail Real Life Example of Separation of Interface & Implementation  Driver has a standard interface to drive a car and using that interface he can drive car of any model or any engine type 18
  • 19. Messages What is a message in OOP?  A message is a request for an object to perform one of its operations (methods)  All Communication between objects is done via messages  The number and kind of messages that can be sent to an object depends upon its interface  The object to which message is addressed (yourBicycle)  The name of the method to perform (changeGear)  Any parameter needed by the method (lowerGear) 19
  • 20. Messages What is a message in OOP? 20 SHOULD WE INCLUDE THIS SLIDE ?
  • 21. Abstraction What is Abstraction?  Abstraction means ignoring irrelevant features, properties, or functions and emphasizing the relevant one  …relevant to the given project (with an eye to future reuse in similar projects) Abstraction = managing complexities 21
  • 22. Abstraction What is Abstraction?  Abstraction is something we do everyday  Looking at an object , we see those things about it that have meanings to us.  We abstract the properties of the object, and keep only what we need.  Abstraction allows us to represent a complex reality in terms of simplified model  Abstraction highlights the properties of an entity that we are most interested in and hides the other 22
  • 23. Abstraction Abstraction Example “Ali is PHD student and teaches BS students”  Here Object Ali has two perspective one is student perspective and other is teacher perspective. Attributes Student Perspective Teacher Perspective Name Employee ID Student Roll No Designation Year of Study Salary CGPA Age  Age is common attribute in both perspectives 23
  • 24. Abstraction Abstraction Example “Ali is PHD student and teaches BS students”  Here Object Ali has different behaviors in student perspective and teacher perspective. Behavior Student Perspective Teacher Perspective Study Deliver Lecture GiveExam TakeExam PlaySports DevelopExam 24
  • 25. Abstraction Abstraction Example “A cat can be viewed with different perspectives”  Here Object Cat has different perspective on Ordinary perspective and Surgeon perspective. Ordinary Perspective Surgeon’s Perspective A pet animal with A being with Four Legs A Skeleton A Tail Heart Two Ears Kidney Sharp Teeth Stomach 25
  • 27. Abstraction Abstraction Advantage  Abstraction has following advantages  Simplifies the model by hiding irrelevant details  Abstraction provides the freedom to defer implementation decisions by avoiding commitment to details. 27
  • 28. 28

Editor's Notes

  • #4: Real Life Examples of Information Hiding Your name and other personal information is stored in your brain we can’t access this information directly. For getting this information we need to ask you about it and it will be up to you how much details you 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 SIM card may store several phone numbers but we can’t read the numbers directly from the SIM card rather phone-set reads this information for us and if the owner of this phone has not allowed others to see the numbers saved in this phone we will not be able to see those phone numbers using phone.