Now I see that the methods written in the model in many frameworks are static methods. When called by the controller, they can be used directly without instantiating the class before calling. How to distinguish whether it is better to use class static methods or object methods
Now I see that the methods written in the model in many frameworks are static methods. When called by the controller, they can be used directly without instantiating the class before calling. How to distinguish whether it is better to use class static methods or object methods
This depends on the type of your method. For example, if your method operates independently of class instances, then it can be set as a static method.
For example, in a tool class, we can set all methods in this class as static methods. At this time, the class is only used to classify our methods. If you want to use ordinary methods, then this class can also use singleton mode.
Tool classes do not require chain operations. I think they can be encapsulated into static classes.
<code>调用方便。</code>