aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes data encapsulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "data encapsulation" Watch "data encapsulation" New topic
Author

data encapsulation

anil gopal
Greenhorn

Joined: May 26, 2003
Posts: 1
Could any one tell me whether there is any other way to achieve data encapsulation than making the attributes private?
Robert Z
Greenhorn

Joined: Jan 18, 2001
Posts: 5
what did you have in mind.. ??
make your membervars private
and use getters and setters..

robert
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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

Joined: Sep 29, 2002
Posts: 1683
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 ]

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
Consider Paul's rocket mass heater.
 
subject: data encapsulation