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):
creating object 1 time , call function using object.
stringmanipulation sm = new stringmanipulation(); sm.reverse("something"); sm.addpadding("something"); sm.addperiod("something");
or
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
Post a Comment