Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data encapsulation

 
anil gopal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could any one tell me whether there is any other way to achieve data encapsulation than making the attributes private?
 
Robert Z
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what did you have in mind.. ??
make your membervars private
and use getters and setters..

robert
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil
Well I guess thats it's not really neccessary to make a data member private for encapsulation. Default access and protected modifier should also do the work. It depends on how tightly encapsulated you want the data in your code to be.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even where you only have package access, it still seems to me that you'd want tight encapsulation. Think of it from a user's point of view: what a pain it would be to have to wade through all the methods and fields to figure out what to do. It's much better to make the relevant methods and fields private, thus enabling the user to focus on what is important, ie what is accessible.
[ May 26, 2003: Message edited by: Roger Chung-Wee ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic