Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the gains of converting normal method to static?

As it is clear from question, if I convert a normal method to static what gains will I made?

like image 824
TheVillageIdiot Avatar asked Dec 10 '22 19:12

TheVillageIdiot


1 Answers

You will gain clarity, because static makes it clear that the method doesn’t depend on an object state. You will also facilitate reusability because static methods may be used in more contexts (i.e. when you don’t have an instance of the class).

In general, it’s not really a question of gain, it’s a question of semantics: does your method depend on the object state? If so, make it non-static. In all other cases, make it static.

like image 130
Konrad Rudolph Avatar answered Jan 28 '23 09:01

Konrad Rudolph