For individuals understanding and using the java embodiment using a single static method

Recently the old module in the reconstruction project, intend to introduce spring boot to the original project their own package dependency injection module replacement. The large number of tools project, mostly prepared using static methods, such as tools for formatting time date, codec for encoding tools. Studied whether it is necessary under these constants based methods reconstructed single embodiment.

First to note is that the function can be achieved in two ways are, just be some differences in some special scene. Unless more interested in, it is generally not necessary to go into too

Differences and features:

Single Example: There are examples, stateful

Static method: None instance, stateless, pure function

Advantage of static methods implementations is highlighted by a simple and crude, no instance of an object, and because the static method is static binding at compile time, the performance will be a little improved. For most business-related tools, really more suitable for such a scenario.

It had significant drawbacks, because they do not instantiate objects, object-oriented design of non-compliance. What internal cohesion and low coupling high, unit testing, to achieve the replacement, AOP proxy, etc. These advantages of object-oriented, they are gone, compared with object-oriented will be more difficult to deal with change.

AOP want to use it, or the use of a single case of it

Guess you like

Origin www.cnblogs.com/feng-gamer/p/11962028.html