• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Abstraction and Encapsulation.

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between these two terms.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
It is said that u really cannot draw a boundary between abstraction & encapsulation.
As per the definition abstraction is selective acceptance. That is u try to find out important properties/behaviour of an real world entity. and keep them as part of ur class to get an object in software domain. that is class attributes & class methods.U keep them together under one class.
But now u may want to keep some attributes or methods very private to urself they are very important. So u dont give direct access to them u provide methods to access them. So u provide a wrapper over it.this is encapsulation
Its just like a capsule u keep the bitter but important part inside & provide a good interface over it. so that it is handy to use. It has great advantages
1. tomorrow if i keep the wrapper same but change the internal data say add a new medicine inside it. User is not affected. He just has to take the capsule the same way he was taking earlier.
See in software domain keeping interface same is very important.
2. Also no one will have direct access to my important data .So it is safe inside.
But now somethings i would like to keep private but some behaviour i would like everyone to share. So i do the abstraction again.I find out things that can be shared out & show them outside whereas private things are again private.To achieve this u provide a wrapper (encapsulate it) using access specifiers.
so abstraction & encapsulation go hand in hand.
e.g.:
a common real world entity:
Car:
Abstraction:
Structural attributes of class car)
I dont need all 10000 parts to represent car in software domain. So i will minimise my window to only parts that i need. Say
stairing
acclerator
wheels
break
fuel pump
piston
Behavioral methods of class car)
start
move
stop
fuel injection
etc
Now all these methods use the attributes to achieve the functionality. But out of these some methods and some parts are internally used by the car & user may not bother @ them.so again do abstraction to find out things that can be directky accesed by user & that which may not be accessed directly.
I hope this will clear ur doubt.
Warm Regards,
meghana.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstraction is omitting noisy details to reveal the important stuff.

Encapsulation is nearly anything you say it is ... or at least every expert has a subtly different definition. You'll find emphasis on information hiding in some places, emphasis on "doing one thing well" in others. I tend to talk about those things separately and consider "encapsulation" to fuzzy to even use in conversation.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic