Does static methods and class are good for scalability ? I think so static class/method improves scalability of application and instance methods doesn't scales much. So is it good programming practice to write static method where ever it is possible ?
A static method belongs to the class rather than the object of a class. A static method can be invoked without the need for creating an instance of a class. A static method can access static data member and can change the value of it.
Static methods are bad for testability. Since static methods belong to the class and not a particular instance, mocking them becomes difficult and dangerous. Overriding a static method is not that simple for some languages.
They are faster — Static methods are slightly faster than instance methods because in instance methods, you are also working with an implicit this parameter. Eliminating that parameter gives a slight performance boost in most programming languages.
In short: Yes. There are many disadvantages and static methods should almost never be used. Static methods allow procedural/functional code to be shoe-horned into an Object Oriented world. Using static methods and variables breaks a lot of the power available to Object-Oriented code.
Does static methods and class are good for scalability?
One has little to do with the other.
I think so static class/method improves scalability of application and instance methods doesn't scales much.
Wrong. Why do you think so?
So is it good programming practice to write static method where ever it is possible?
No. In fact, it is very bad practice because it abandons the maintainability advantages of object-oriented programming.
It depends on WHY the method is static. If it's static because it truly does not need context, then it will probably scale very well compared to something of similar complexity that is not static because it requires context.
However, if it is static merely because you cannot retain the needed context and must still pass it in, or because of some artificial goal of having more static methods, then I would suspect that it will actually scale LESS than the comparable method as non-static.
In fact I think that ASP Classic proved this point.
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