一个可观察的类可以被构造为单例吗? [英] Can an observable class be constructed as a singleton?

查看:81
本文介绍了一个可观察的类可以被构造为单例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Observer模式在Java中编写程序(借助Java API)。如果一些可观察者有多个实例,程序可能会崩溃。我应该把它们实现为单身吗?是推荐吗

解决方案

我以前做过,没有任何问题,正是因为我使用了单身人士。
模式是使用它。


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?

解决方案

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

这篇关于一个可观察的类可以被构造为单例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆