What is an efficient way to implement a singleton pattern in Java? [closed]

Use an enum: public enum Foo { INSTANCE; } Joshua Bloch explained this approach in his Effective Java Reloaded talk at Google I/O 2008: link to video. Also see slides 30-32 of his presentation (effective_java_reloaded.pdf): The Right Way to Implement a Serializable Singleton public enum Elvis { INSTANCE; private final String[] favoriteSongs = { “Hound … Read more

C++ Singleton design pattern

In 2008 I provided a C++98 implementation of the Singleton design pattern that is lazy-evaluated, guaranteed-destruction, not-technically-thread-safe: Can any one provide me a sample of Singleton in c++? Here is an updated C++11 implementation of the Singleton design pattern that is lazy-evaluated, correctly-destroyed, and thread-safe. class S { public: static S& getInstance() { static S … Read more

What are MVP and MVC and what is the difference?

Model-View-Presenter In MVP, the Presenter contains the UI business logic for the View. All invocations from the View delegate directly to the Presenter. The Presenter is also decoupled directly from the View and talks to it through an interface. This is to allow mocking of the View in a unit test. One common attribute of … Read more