java - Better way to call Function multiple times -


this question has answer here:

in oop such c# , java if create class string manipulation, know better make function static. when need call functions multiple times, 1 better option (in context of using less resources):

  1. creating object 1 time , call function using object.

    stringmanipulation sm = new stringmanipulation();  sm.reverse("something"); sm.addpadding("something"); sm.addperiod("something"); 

or

  1. calling class directly everytime

    stringmanipulation.reverse("something"); stringmanipulation.addpadding("something"); stringmanipulation.addperiod("something"); 

the performance differences of give 2 options negligible. main difference in usage of methods.

if need method general tasks independant of class objects consider static methods in design. else object dependant tasks should consider instance methods.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -