Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.
Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.
Stats
| Reputation: | 198 |
| Pageviews: | 246.6K |
| Articles: | 3 |
| Comments: | 5 |
Comments
Dec 12, 2015 · Davide Lorenzo Marino
The singleton pattern is a design pattern that restricts the instantiation of a class to one object.
In software engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction.
Both definitions are taken from wikipedia.
So why you said that this is not a singleton, but a pojo? I don't understand.
Dec 11, 2015 · Davide Lorenzo Marino
There are context in wich you need to know how to build a singleton:
- when the customer like to have to total control of the code
- because introducing a framework is not compatible with performance aspects
- because somebody will ask you how to create a singleton in a job interview
- you are creating a framework and you need to expose singletons
- for personal curiosity
Dec 10, 2015 · Davide Lorenzo Marino
Thanks for the reference to the JLS specifications
Dec 10, 2015 · Davide Lorenzo Marino
In most situations the eager implementation is the best one. Also the enum solution proposed by Ondrej is a good one. But the eager one will be loaded always also when is not used only because you import the class. The process of class loading will create the singleton instance also if never used. All the lazy implementations will be loaded only on demand.
Dec 10, 2015 · Davide Lorenzo Marino
Yes enum is another possibility from java 1.5 because the instantiation is thread safe.