Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Singleton using Static Members and Methods? [duplicate]

Tags:

java

oop

We can replicate a Singleton behavior my making a Class with Static Methods and Member Elements. Other than serialization What's the harm of implementing a singleton using static Body only.

like image 707
Vivek Vermani Avatar asked Jan 24 '14 03:01

Vivek Vermani


1 Answers

You can't use this pattern to implement a provider for some interface or to allow for subclassing or other alternate behavior. This means that testing becomes more difficult and you can't use dependency injection for anything your static class does.

like image 101
chrylis -cautiouslyoptimistic- Avatar answered Oct 16 '22 01:10

chrylis -cautiouslyoptimistic-