0

I know about singleton pattern, but what is special about it, that makes it so distinct from other design patterns, in android. I have reviewed several android interview questions and most of them mention singleton, even android studio has an option to create singleton class.

Mr.Q
  • 4,316
  • 3
  • 43
  • 40
  • This is sort of like asking what is "special" about a rock in a desert. What kind of "special-ness" are you asking about? – Stephen C Jul 18 '16 at 07:41

2 Answers2

0

Although singleton has some different realization ways,I think it is same as in Java.

wuyue
  • 1
0

Suppose you want to limit the number of instances your class can spawn to exactly one, you use a singleton pattern.

Now this can be beneficial in a number of situations eg- you want to use your class object in a threaded environment but don't want to handle each threads own instance, you can use a singleton pattern. Or say you want multiple users running on multiple threads to be authenticated using one class object which has your algo ,etc...

eg-> you want only one calender to exist for everybody(makes sense right?), here java uses a Calender class as a singleton thus giving access to only one instance and not allowing anyone to instantiate one of their own.

It has specific importance only when you actually need it. It on the other hands also has some drawbacks like changing something at one place will reflect in all the usages.

Use it according to your own needs :)

Kushan
  • 5,855
  • 3
  • 31
  • 45