Note that there are some explanatory texts on larger screens.

plurals
  1. PONon-AOP Best Practices for Application-Wide Singletons
    primarykey
    data
    text
    <p>[Java]</p> <p>I have several utility classes that will appear all over my code (LogHelpers, Exception Handlers, CacheHelpers, etc.) that all represent "cross-cutting concerns" and would be ideal candidates for AOP except... I don't have the time to learn AOP frameworks like AspectJ or AOP Alliance or Google Guice.</p> <p>Having said that, I'd still like my code to be as neat and clean and in keeping with best-practices (non-AOP best practices that is!) as possible.</p> <p>I have two problems that probably require two solutions. The first is that I have a few of these universal/highly-coupled/AOP-candidate classes that just require static methods; the classes themselves don't have any non-static/instance-level methods. Things like ExceptionHandler.handleException(Exception exc).</p> <p>The second problem is that I have a few of these universal/AOP-candidate classes that do have method instances, and do need to be instantiated, but are probably best served as singletons, where my application creates one "global" instance of them and the same reference is used throughout the other packages and codebase.</p> <p>Sooo...</p> <p>My question is: what are the best (non-AOP) design patterns &amp; practices for classes that:</p> <p>(a) Only define static methods consumed all over the codebase; and (b) Only need to one single instance that will be consumed all over the codebase?</p> <p>Singleton pattern? Factory? Static imports? Other?!?!</p> <p>Thanks for any suggestions here!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload