aspose file tools*
The moose likes Beginning Java and the fly likes accessor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "accessor" Watch "accessor" New topic
Author

accessor

Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
People said that we should provide accessor methods for attribute, and make the attribute private. I've been programming with Java for some time but still can't really understand the reason for that. Can someone help me?
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Susilo
Actually,a daily example can be used.
If my things are public,such as money,house and chicken feet which I always use,so all the people can use my thing if they know my address or they see me.What are the problems? All the things can not be protected(secured),if I want to protect my (right of chicken feet) .So,the thing I do not want to share with other people that should be used private.And if other people want to use it,they should get the agreement with me and use the legal method (getter method) to get the license . So,some variables should be considered in which accessible modifier is used.It is related to design.
hope this chicken feet help
[ May 27, 2003: Message edited by: siu chung man ]

Francis Siu
SCJP, MCDBA
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Excellent job siu! I know I'll ask before grabbing your chicken feet now.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
I know I'll ask before grabbing your chicken feet now
Free license of chicken feet is available to all ranchers
And I am grateful if you can tell me the meaning.

Is it related to your recruit?
Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt
[ May 27, 2003: Message edited by: siu chung man ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The reason we make properties private and supply accessor methods is so that we can control access to the properties. Imagine we have a property in our Employee class for annualSalary. If we make it public then anyone can change it to anything they like. A few months later we find that somehow annualSalary is sometimes being set to a negative value. So we decide to change the property to private and add an accessor. But everyone who has used our class will have to change their code!!! We will have made many enemies. Much better to use the accessor right from the start even if it does nothing except update the property without doing any checking.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
Great replies, Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessor
 
Similar Threads
?(inheritance) from a newbie
CMR and EJBQL
WebSphere V5 CMP create problem
Calling method in the outputText value attribute
EL to display bean attribute evaluates to null