• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Getter/Setter vs Private

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

Originally posted by Vladas Razas:

there is no point of making everything reusable (since it's only guessing anyways) plus it burns incredible amounts of time.



Please consider the role of your code and your coders. Again: are you really a bean provider? (Not just an internal framework provider!) Then and only then you could think of reusing and inheriting code in unpredictable ways.

For Non-bean-provider-code normally your team is the owner of the code, and as soon as anything needs to be changed from private to public, your team knows all the possible interferences better than anyone else.

Therefore provide as few public members (methods and for instance attributes) as possible first. Otherwise burning incredible amounts of time is just one reason. Stability and robustnes are more reasons.

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

Therefore provide as few public members (methods and for instance attributes) as possible first. Otherwise burning incredible amounts of time is just one reason. Stability and robustnes are more reasons.



I had that practice to make everything private and then "raise" access levels. But what happens when developer is no longer using that getter? I think 95% chance he will not go into my class, check if anybody else uses the getter and then hide it back.
Currently I do it this way: I do make getters for everything that could be reasonably got. The limits of "the reason" I have to decide myself Some of my classes are as containers to other objects, i.e. I have UI panel it contains buttons, text fields etc. In this case I give them all to the user with getters. Some other classes just do their job. They are not supposed to act as containers. In that case I do not give away any getters. Some classes are mix of both cases.
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I had that practice to make everything private and then "raise" access levels.



Mistake. I did not raise access level but did provide getter. Or raised access level to existing getter.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vladas Razas:
Maybe it depends on type of the project? When we develop final product with source code open for modification we can save time. But if we develop library then code must be more flexible than average.



But it's very hard to develop a library that's flexible exactly in the way the users need it. It's quite easy to make it more complex then needed and still not provide basic vital functionality. In my experience, the best way to write a library is to extract it from common code of a number of clients.
 
pie. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic