Tuesday 10 December 2013

Why we introduce encapsulation in OOP? Differentiate Encapsulation, Data hiding, Data abstraction.

In procedural language, We create some public variable and that variable is access by any function. Suppose one function is used that variable but ideally that function should not access that variable. We get error at debug time and we correct that error.
Reduce to above problem, OOP introduce on concept is call encapsulation. In encapsulation we combine variables with functions (Which functions that used that variables). Now some other function can not able to access that variable directly and ours problem is solved now. 

Encapsulation is process of combining variable and function into one capsule (OOP term is called class) and access them using function (Like that both are one entity).

Data Hiding  is process of hiding data through Private access specifier and it can not accessible directly outside. If you want to access that variable then we write relevant function to access that variable.

Data Abstraction is process of hiding programming complexing from user. It can be implemented at class level, function level or package level. In class level data abstraction, you make some function are private that private function can not visible to user and some function as public which can be access by user. So hide unwanted complexity through private function is call Data Abstraction.

No comments:

Post a Comment