Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

difference between accessing class constructor and method in the class  RSS feed

 
narasimharao konjeti
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every one.
I have one query in terms of performance.

calling the class constructor is expensive and calling the method in the class is expensinsive in terms of performance.

which one is better to pass the parameter.

i.e overloaded class constructor or class method.

waiting for reply.

regards
narasimha rao konjeti.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an object, you may only call the constructor once, and make your design-decision on this fact.

To compare performance, make a prototyp and test.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking, it is memory allocation that takes up the most time in object construction.
Of all the reasons to decide between a no-args constructor and one with arguments, performance is so far down the list that it is invisible.
Your architecture should strive for maximum clarity and maintainability and not chase after supposed microscopic performance improvements.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!