• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

when to use property or parameter?

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

is there a rule (or heuristic) when to set up a property instead of using a parameter in methods signature?

for example:







 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never heard of such a rule. In the first case, the object "knows" whether it needs to be updated. In the second case, you are telling the object it needs updating willy-nilly. Different designs.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Different designs...yes indeed..and I have the problem to decide which design is better.

What do you think?

In functional manner I would take design nr. 2 ("update" as a parameter) - so I do not need to have a getter/setter for "update" in a object - what do you think?
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That deppends on who has the knowledge, who says that that object has to be updated? The User or the program?

In the first case the User asks itself 'hey, do I have to update?' wheras in the second the program says 'hey, do I have the conditions?... yes... then you update!'

Both are ok deppends on your application.

Other thing, why do you use Boolean instead of boolean?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That deppends on who has the knowledge, who says that that object has to be updated? The User or the program?



The User can set the property too, instead of using a parameter..is it good to encapsulate all in properties instead of using obsolete parameters?


I use Boolean because everyman says.."hey use the Wrapper Objects instead of primitive types"..I do not really know, when to prefer the one or the other. However, look at other programming languages such as scala where everything is (or should be) a object. So I use always the wrapper types, in this case Boolean instead of boolean. Is that bad?


 
Albareto McKenzie
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nimo frey wrote:

That deppends on who has the knowledge, who says that that object has to be updated? The User or the program?



The User can set the property too, instead of using a parameter..is it good to encapsulate all in properties instead of using obsolete parameters?



What do you mean with obsolete parameters?
I think both are correct, you have to think in the flow of your application and look who has to order the object to be updated.

nimo frey wrote:
I use Boolean because everyman says.."hey use the Wrapper Objects instead of primitive types"..I do not really know, when to prefer the one or the other. However, look at other programming languages such as scala where everything is (or should be) a object. So I use always the wrapper types, in this case Boolean instead of boolean. Is that bad?




I have never heard that about using the Object instead of the primitive, if you look at the Boolean class http://java.sun.com/javase/6/docs/api/java/lang/Boolean.html it's doing references to the primitive type all the time.
 
reply
    Bookmark Topic Watch Topic
  • New Topic