Top Banner
Information Hiding
20
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Oop

Information Hiding

Page 2: Oop

Group Members

• Sameen• Nazia

Page 3: Oop

By Information Hiding we mean “Showing only those details to the outside world which

are necessary for the outside world and hiding all other details from the outside world.”

Page 4: Oop

Real Life Examples of Information Hiding

• Sameen’s name and her personal information is stored in her brain you can’t access this information directly. For getting this information we need to ask Sameen about it and it will be up to Sameen how much details he would like to share with you.

• We have multimedia in our class, we saw the working of multimedia that we use it to share our ideas and teachers use it to deliver their lectures. But we do not know about its internal functions.

Page 5: Oop

• 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.

Page 6: Oop
Page 7: Oop

Advantages of Information Hiding

• There are two major advantages of information hiding which are as follows:

It simplifies our Object Oriented Model:As we saw that our OO model had objects and their interactions hiding details so it makes it easier to understand our OO model.

It is a barrier against change propagation:As implementation of functions is limited to our class and we have given name of functions to user with description of parameters so if we change implementation of function it doesn’t affect the OO model.

Page 8: Oop

Information hiding using Encapsulation and Abstraction

•Encapsulation

•Abstraction

Page 9: Oop

Encapsulation

• Encapsulation means “we have enclosed all the characteristics of an object in the object itself”.

• Encapsulation is a mechanism of bundling the data, and the functions that use them.

• Both the information structure and implementation details of its operations are hidden from the outer world.

Page 10: Oop

Examples of encapsulation:

Page 11: Oop

• 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

Page 12: Oop

• We know the name of Ali and knows he can walk and eat but we do not knows his personal information.

Page 13: Oop

• A Phone stores phone numbers in digital format and knows how it works, we do not know internally about phone.

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

characters.

Page 14: Oop

Internal view External view

Page 15: Oop

Advantages of Encapsulation

• Simplicity and clarity

• Low complexity

• Better understanding

Page 16: Oop

Abstraction

• Real life objects have a lot of attributes and many kind of behaviors but most of the time we are interested in only that part of the objects that is related to the problem we are currently going to solve.

• We also say that “Capture only those details about an object that are relevant to current perspective”

Page 17: Oop

Example of Abstraction

• If our data required organisms, mammals, humans then we have

Page 18: Oop

• If our data required organisms, mammals, dangerous mammals then we have

Page 19: Oop

• A cat can be viewed with different perspectives

Page 20: Oop

Abstraction – Advantages

• It helps us understanding and solving a problem using object oriented approach as it hides extra irrelevant details of objects.

• Focusing on single perspective of an object provides us freedom to change implementation for other aspects of for an object later.