Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getter setter

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Krithika Srinath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Krithika

Please refer to the Javaranch's naming policy.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic