Abstraction and Encapsulation

cheezycode 1,304 views 10 slides Dec 26, 2015
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

What is Abstraction and Encapsulation? Learn by simple example of what is encapsulation and what is abstraction.
Very common interview question and Part of Object Oriented Programming.

Watch Video to understand it well - https://www.youtube.com/watch?v=OCR1i0H-0YM

Visit our site -
http://www.chee...


Slide Content

ABSTRACTION AND ENCAPSULATION

ABSTRACTION Ignoring those aspects of an object that are not relevant to the current scope of the problem. Reduces scope and helps managing complexity.

ABSTRACTION Designing a website to sell new Cars. Car Description Type Price …

ABSTRACTION Do I need to include Service History as a field? No (Because it does not belong to new car and is not relevant to current scope) Do I need to include Vehicle Registration Number as a field? No (Because currently we do not have and it’s not necessary currently. You get the number after you buy the car.)

ABSTRACTION EXCLUDE WHICH IS NOT RELEVANT TO THE CURRENT SCOPE

ENCAPSULATION Provides interface to access the functionality of the object & hides how it is implemented. Keep the attributes and behavior as one unit – Helps to make it more independent.

ENCAPSULATION Example of Pressing ’A’ on Keyboard. Keyboard Press A --- 65 1000001 Laptop

ENCAPSULATION Keys are exposed as interface and as an end user when I press ‘A’, it is printed on the screen. I do not know how it is implemented. Implementation is hidden as to how it displays that on screen. Hiding implementation has a benefit – you can change the implementation later but you can still have the same interface. Maintenance is easy.

ENCAPSULATION Other aspect of attributes and behavior as one unit is it helps to make the object independent. As a programmer, you know when you press A , 65 (ASCII) is sent as signal but for end user it does not matter. 65 is hidden from end user and it is private to Keyboard object, only inner methods have access to it. This keeps them as one unit and encapsulated.

CONCLUSION Abstraction comes before Encapsulation In Abstraction, we are trying to come up with the scope of the problem. In Encapsulation, we are trying to come up with the approach to solve and implement problem in a better way.