New answers tagged

-1

Make your loader static and put your load function in the static constructor. Then when the static constructor is called the list will be loaded and essentially cached in the static list until the application is unloaded. This will ensure your data is loaded once since static constructors are thread safe. For testing proposes you could put an interface ...


0

The problem with static singletons is not the global state per se, it is that they are usually used for shady things. One of the most common examples is is a database connection. Static singletons are wrong for one main reason: you can get an instance of an instance the singleton wraps anywhere in the application, in any class, without ever letting a user ...


0

"One of the problem of using the singleton pattern is global state" If you use it for global state then you can do so. But that does not affect the "singleton pattern" itself as it is answering the question how many instances of an object there may be: One. "global" and "state" do not adress the question "How many instances may be there?". They adress the ...



Top 50 recent answers are included