单身人士模式有什么缺点吗? [英] Are there any downsides to the singleton pattern?

查看:249
本文介绍了单身人士模式有什么缺点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能的重复:

单身人士的情况如何糟糕?

单身人格模式的问题

单身形式有什么缺点吗?我听说这是一个采访问题,而我正在简短介绍一下什么意思。

Are there any downsides to the singleton pattern? I heard this was an interview question and i am coming up short on what was meant.

imho,这是关于使用,而且模式本身没有任何问题。 >

imho, it's about the usage and nothing in the pattern itself is problematic

推荐答案

Wikipedia


有些人认为它是一个反模式
判断它是过度使用,

的情况下引入了不必要的限制,其中一个
类的唯一实例实际上不需要,而
将全局状态引入
应用程序。

Some consider it an anti-pattern, judging that it is overused, introduces unnecessary limitations in situations where a sole instance of a class is not actually required, and introduces global state into an application.

个人而言,由于我已经开始使用Spring自动连线我的应用程序,所以我从来没有必要编写单例。

Personally, since I've started using Spring to auto-wire my application I've never had the need to write a singleton.

这篇关于单身人士模式有什么缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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