I have a member function that does not depend on any member variables of the class. (in my case the class is an ASP.Net Page)
The function is protected, I dont need it outside of this class. Its only purpose is to build an URL from an given object.
Should I make all my functions static if they dont depend on the class, even if they are not used outside of this class? Is there any reason like performance or maintainability to do so?
Probably, but I'd take it a step further.
In these situations you really want to ask yourself if the method still belongs with the type at all. If this method has no dependence on the type's data, why is it part of that type? Is there a better or more appropriate type? Do you have several of these, perhaps scattered among a few different types, that could be logically grouped together?
It is good practive to make functions that don't interact with member data static. It just helps describe how the function interacts with its environment. There should be no performance issues though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With