• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use of encapsulation

 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Encapsulation means wrapping up of member data and member functions together and this is a feature of OOP.
But,what it the benefit we are getting by using encapsulation or in other words what we will be loosing if not using encapsulation.
thanks in advance.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raj,
There are several advantages of encapsulation.
The primary advantage is data access and managing data for a specific entity/Object.
Encapsulation allows you to bind the data within the object and provides set of operations to manipulate the data.

I'm not sure whether you are happy with my answer but you'll understand practically if you write one C program and java program for same requirement like managing employee data.

Thanks,
Sam
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main advantage of encapsulation is that it keeps your code maintainable. By keeping things that are closely coupled also close together in the source code, it becomes easier to assess the impact of changes to the code.

For example, imagine that a value that until now has been stored in a field should now be calculated one the fly from the value of another field. That's easy to do if the field is only directly accessed from inside the class and all other clients go through methods. Without encapsulation, it can even become impossible - especially when not all clients are under your direct control.

Does that help?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic