Java – are there any side effects of using many static functions?

At present, I am very interested in game framework because it can promote faster development

When I see the code, there is a lot of static code Even the controller is declared as a static function Therefore, must all code that calls internal static functions be static?

My question is, is this right? Are there any side effects of using many static functions?

Solution

Some things about static methods in object - oriented languages: if you choose to use all static methods, let me try to explain the problem

It may not be customary to use all static functions in object - oriented languages You cannot override static functions in a class Therefore, you cannot perform runtime polymorphism by overriding

The variables you define will automatically become class variables (because all your methods are static), so basically you don't have any state associated with the instance

Static methods are difficult to simulate You may need a framework like powermock to simulate for you Therefore, testing becomes difficult

The design becomes a little complicated because you will not be able to create immutable classes because you actually have only classes and no instances Therefore, designing thread - safe classes becomes difficult

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>