When creating a Util class in a CDI environment, which of the following 1-3 would be the best?
I'm thinking about performance and convenience (compatibility with JUnit), but I can't answer which one is better.
1.static class
2. ApplicationScoped Class
3. Other than the above
It depends on what the tUtil class かに refers to, but if you don't have a state (variable instance variable), I think 」1. で would be fine.
For utility classes (such as Apache Commons Lang), implementing common state-independent operations using the static method alone is common (no state).
@ApplicationScoped
is used to maintain a state shared by the entire user of the application, such as the value in the drop-down list.
I think that's the standard of selection.In terms of convenience, it is often better to have a utility class that does not require a container or other prerequisite software.The impact on performance does not seem to change significantly depending on the choice between 1 and 3 (depending on implementation).
© 2024 OneMinuteCode. All rights reserved.