Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between data encapsulation and data abstraction

 
Suresh KumarPandey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the exact difference between data abstraction and encapsulation.

According to me using encapsulation we provide the users which are using my class to access the variables through a public method there by hiding the implementation details and if i would need to change anything in my methods i can do it woithout breaking others code.

Data abstraction is used for loose coupling so that we can make reusable codes.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh KumarPandey wrote:

According to me using encapsulation we provide the users which are using my class to access the variables through a public method there by hiding the implementation details and if i would need to change anything in my methods i can do it woithout breaking others code.

Data abstraction is used for loose coupling so that we can make reusable codes.


Both of those is what is meant by abstraction. Abstraction helps us deal with complexity. The caller of an API need not know how the API implements what it provides. For example, when we type System.out.println("some string"); it prints whatever we specify. We needn't ( and most often we shouldn't ) bother ourselves with how it does that printing.

Abstraction makes our life easy by hiding complexity and letting us focus on only those parts which are important for what we are dealing with.

Encapsulation is merely the wrapping up of data and methods that operate on this data together. Classes for example wrap together the data and the methods that operate on the data they contain. Encapsulation helps us wrap things that interact together in one logical, cohesive unit. This wrapping up of data and methods should be smart so that each wrapper is associated with a specific responsibility only. I think encapsulation is very similar to normalization ( the one we studied in databases ) in that respect.

 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encapsulation is merely ...


For me seeing these two words side by side is difficult to digest. For anyone who programmed in C for years and had hundreds of methods and plenty of data structures floating around encapsulation is _huge_.

Regards,
Dan
 
Shubham Semwal
Ranch Hand
Posts: 154
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh KumarPandey wrote:what is the exact difference between data abstraction and encapsulation.
.


As far as i understand they go side by side. First you encapsulate and then it's abstracted.
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I look at it is encapsulation is an OOP concept, not really tied to any implementation, whether it is Java, Slang, C++ or C ( I included C cause many people consider that C supports true encapsulation - enough has been said on this - so I will not contribute more and also I can't be sure cause I haven't programmed in C for many years ), or any other programming language for that matter.

I think a well encapsulated wrapper protects data, i.e it provides data hiding, which is crucial for any object oriented implementation cause data is what constitutes the state of an instance. The goal is to not reduce the complexity, but to protect data.

Yes abstraction also hides details, i.e the implementation details. The goal here is, though, to reduce complexity. And it is the 'how' ( the implementation ) that is hidden, not 'what' as in the case of encapsulation.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic