Object-Oriented Programming
(OOP)
Lecture No. 2
Information Hiding
• Information is stored within the object
• It is hidden from the outside world
• It can only be manipu...
Example – Information Hiding
• Ali’s name is stored within his brain
• We can’t access his name directly
• Rather we can a...
Example – Information Hiding
• A phone stores several phone numbers
• We can’t read the numbers directly from the
SIM card...
Information Hiding
Advantages
• Simplifies the model by hiding
implementation details
• It is a barrier against change pro...
Encapsulation
• Data and behaviour are tightly coupled inside
an object
• Both the information structure and
implementatio...
Example – Encapsulation
• Ali stores his personal information and knows
how to translate it to the desired language
• We d...
Example – Encapsulation
• A Phone stores phone numbers in digital
format and knows how to convert it into
human-readable c...
Encapsulation – Advantages
• Simplicity and clarity
• Low complexity
• Better understanding
Object has an Interface
• An object encapsulates data and behaviour
• So how objects interact with each other?
• Each obje...
Example – Interface of a Car
• Steer Wheels
• Accelerate
• Change Gear
• Apply Brakes
• Turn Lights On/Off
Example – Interface of a Phone
• Input Number
• Place Call
• Disconnect Call
• Add number to address book
• Remove number
...
Implementation
• Provides services offered by the object
interface
• This includes
– Data structures to hold object state
...
Example – Implementation of Gear
Box
• Data Structure
– Mechanical structure of gear box
• Functionality
– Mechanism to ch...
Example – Implementation of
Address Book in a Phone
• Data Structure
– SIM card
• Functionality
– Read/write circuitry
Separation of Interface &
Implementation
• Means change in implementation does not
effect object interface
• This is achie...
Example – Separation of Interface
& Implementation
• A driver can drive a car independent of engine
type (petrol, diesel)
...
Example – Separation of Interface
& Implementation
• A driver can apply brakes independent of
brakes type (simple, disk)
•...
Advantages of Separation
• Users need not to worry about a change until
the interface is same
• Low Complexity
• Direct ac...
Messages
• Objects communicate through messages
• They send messages (stimuli) by invoking
appropriate operations on the t...
Examples – Messages
• A Person sends message (stimulus) “stop” to a
Car by applying brakes
• A Person sends message “place...
Upcoming SlideShare
Loading in …5
×

Oop + lecture02

218
-1

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
218
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oop + lecture02

  1. 1. Object-Oriented Programming (OOP) Lecture No. 2
  2. 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. 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
  4. 4. Example – Information Hiding • 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
  5. 5. Information Hiding Advantages • Simplifies the model by hiding implementation details • It is a barrier against change propagation
  6. 6. Encapsulation • Data and behaviour are tightly coupled inside an object • Both the information structure and implementation details of its operations are hidden from the outer world
  7. 7. 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
  8. 8. 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
  9. 9. Encapsulation – Advantages • Simplicity and clarity • Low complexity • Better understanding
  10. 10. Object has an Interface • An object encapsulates data and behaviour • So how objects interact with each other? • Each object provides an interface (operations) • Other objects communicate through this interface
  11. 11. Example – Interface of a Car • Steer Wheels • Accelerate • Change Gear • Apply Brakes • Turn Lights On/Off
  12. 12. Example – Interface of a Phone • Input Number • Place Call • Disconnect Call • Add number to address book • Remove number • Update number
  13. 13. Implementation • Provides services offered by the object interface • This includes – Data structures to hold object state – Functionality that provides required services
  14. 14. Example – Implementation of Gear Box • Data Structure – Mechanical structure of gear box • Functionality – Mechanism to change gear
  15. 15. Example – Implementation of Address Book in a Phone • Data Structure – SIM card • Functionality – Read/write circuitry
  16. 16. Separation of Interface & Implementation • Means change in implementation does not effect object interface • This is achieved via principles of information hiding and encapsulation
  17. 17. 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
  18. 18. Example – Separation of Interface & Implementation • A driver can apply brakes independent of brakes type (simple, disk) • Again, reason is the same interface
  19. 19. 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
  20. 20. Messages • Objects communicate through messages • They send messages (stimuli) by invoking appropriate operations on the target object • The number and kind of messages that can be sent to an object depends upon its interface
  21. 21. Examples – Messages • A Person sends message (stimulus) “stop” to a Car by applying brakes • A Person sends message “place call” to a Phone by pressing appropriate button
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×