Search code examples
javasingletondesign-patternsobserver-pattern

Can an observable class be constructed as a singleton?


I'm making a program in Java with the Observer pattern (with the help of the Java API). If some of the observables had more than one instance, the program could crash. Should I implement them as singleton? Is it recommended?


Solution

  • I did it before and didn't have any problems exactly because I used a singleton. The pattern is there to use it.