Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Difference between data encapsulation and data abstraction

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
grapes are vegan food pellets. Eat this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic