aspose file tools*
The moose likes Servlets and the fly likes keeping variables private in a bean. 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 » Java » Servlets
Bookmark "keeping variables private in a bean." Watch "keeping variables private in a bean." New topic
Author

keeping variables private in a bean.

Ed Gandy
Greenhorn

Joined: Aug 04, 2001
Posts: 9
I have got a bean CraneAsset, which extends Asset.
"Asset" has a property called "assetNum" and appropriate get/set methods.
When I create a CraneAsset bean and use getAssetNum, I got a message that "assetNum" is a private variable in the superclass "Asset". So I went back to the "Asset" and changed "assetNum" to "protected".
But making it "protected" to get "assetNum" to inherit down to the subclass properly defeats the whole purpose of keeping all bean variables "private". Now another class in the same package can access the variable with Classname.assetNum.
Is there a way around this dilemma?
thanks, - ed g.
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
keep the variable private & get the contents of the variable into the subclass by calling the appropriate get method of the variable in the superclass.
Correct me anybody if I am wrong.
Originally posted by Ed Gandy:
I have got a bean CraneAsset, which extends Asset.
"Asset" has a property called "assetNum" and appropriate get/set methods.
When I create a CraneAsset bean and use getAssetNum, I got a message that "assetNum" is a private variable in the superclass "Asset". So I went back to the "Asset" and changed "assetNum" to "protected".
But making it "protected" to get "assetNum" to inherit down to the subclass properly defeats the whole purpose of keeping all bean variables "private". Now another class in the same package can access the variable with Classname.assetNum.
Is there a way around this dilemma?
thanks, - ed g.

Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Hi,
Yes Roopa is right. Here's a little example I did to be sure it worked:

You can declare Sub.x private in your bean. I couldn't here 'cos I wanted Super to print it out for debugging.

Bye,
------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Terence Doyle (edited October 12, 2001).]


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Ed Gandy
Greenhorn

Joined: Aug 04, 2001
Posts: 9
thanks for the help. i will implement the suggestion. - ed g
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: keeping variables private in a bean.