• Post Reply Bookmark Topic Watch Topic
  • New Topic

About performance and memory usage  RSS feed

 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
If I use an object with a lot of getters and setters (e.g 100) instead of an object with just 1 getter and 1 setter, is it poor in performance and memory usage? (At runtime, only 1 getter and 1 setter will be called on each object).
Thanks,
Jack
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your question.
Moving this to the Performance forum...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also have no idea what you're asking. Perhaps a little bit of code to illustrate how having one getter and 100 getters could be alternate implementations of the same class?
 
stephan schweitzer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
I also have no idea what you're asking. Perhaps a little bit of code to illustrate how having one getter and 100 getters could be alternate implementations of the same class?

Alternative 1 (one getter/setter):

Alternative 2 (n getter/setter):

Not very clever and elegant perhaps (it depends on the context i think)
but these code fragments are alternative implementations for the same
class.
I think the question of Jack is if the number of methods of a class has
any impact to the performance. I think the number of methods influences
only the size of the class file (and so the time needed to load the class)
and the size of the vtable (but this should not influence performance).
I hope this helps
Stephan
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack,
If the getters and setters are just getting/setting a field, there shouldn't be a performance difference. (or if there is it would be tiny)
However, the getters/setters are transferring data across a network, it is better to make one call. This happens in frequently in EJBs.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!