my dog learned polymorphism*
The moose likes Beginning Java and the fly likes getter setter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getter setter" Watch "getter setter" New topic
Author

getter setter

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Hello!


You cannot avoid getters/setters totally especially not at the "borders" of the application where you exchange data with different sources, but you can avoid them almost entirely at the "center" where you have your own classes concerned with the so called business logic of the application.


business logic?!!

May some one explain more about it?
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
Business Logic is a term used to describe logic which "runs" your application. It's generally spoken about when people are describing a common design pattern -- MVC, where the objective is to separate business logic from presentation logic (separate the complex bulk of the code from the more simplistic template which displays the results).

Business Logic is a board term for accessing the database, dealing with request parameters, working with beans and so on.... (anything that's not visual).
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I do not think that there is anything deep to think about this.
It has been cotectly mentioned that its used primarily for exchange of data , no business logic , but at times I have seen it to contain some validation stuff.Thats ok I guess.


Rahul Bhattacharjee
LinkedIn - Blog
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Re avoiding getters and setters ... it's generally better when an object keeps its internal workings secret and private. When we can get and set variables we start to know (or infer or guess) more and more about how the object works. That's bad, because we use perfectly good brain cells learning things we shouldn't have to know and it makes it harder to change that object if a new business rule or algorithm comes along.

Here and here are some amusing stories that show some of the goodness of keeping things private.

Let us know if that raises more questions!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Krithika Srinath
Ranch Hand

Joined: Apr 11, 2006
Posts: 52
Hi Stan,

Thanks very much for great references. I was looking for some other details and got a very good architectural view points.

Regards
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Hi Krithika

Please refer to the Javaranch's naming policy.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
I know one of the usage of getter setter is that transfer data between classes,



Please give an example ,How to use getter setter for this aim?
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Hello Again,

Anyone give a simple example about that?How getter/setter use for that goal?Which condition must be cared for this case?

Thanks in advance for the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getter setter