Overview
Like in Vb,c#,c,c++,java we can see that static appears as a keyword and function in other advanced computer languages such as Fortran, ALGOL, COBOL, BASIC, LISP, Snobol, PL/1, Pascal, PROLOG , Ada and other languages are also appearing, but have different roles, for its specific role, the reader has the need for the time can be specifically consulted.
Understand
The static keyword is indeed a keyword for the era of process development, but it does not mean that the static keyword should be avoided as much as possible in object-oriented development.
Static class and non-static class effect is certainly not the same, there must be some difference.
The static class is typically used for state-independent classes. So, what is a state-independent class? My understanding is that when there are no attributes in a class, only the method can be considered a class that is not state-independent. Recall that a non-static class instantiates an object, where is the purpose? The purpose is to save the state of the class through this instantiated object.
Isn't it? For example
A = new A (); a.name = "Kevin"; a.sex = "male";
The state of the class is persisted by object A through the object a that we instantiate.
If our class has no attributes and is all methods, then is it necessary to instantiate an object in order to invoke the method in the class?
Therefore, I suggest that, in the design of the class, if the class is a state-independent class, it is recommended that it be designed as a static class.
As for the meaning of this: first, the performance loss of constructing an object is omitted, although it can be neglected. Second, the programmer is more friendly, the method of invoking the class is more convenient.
Summary
As long as a class is a class independent of the State class, it is no problem to design it as a static class.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Static in C #