本文介绍了误用的设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在规范的四人一组"列表中,您是否经常发现任何滥用,误解或过度使用的设计模式(激烈争论的Singleton除外)?换句话说,有没有建议您在使用之前仔细考虑的设计模式? (为什么?)
Are there, in the canonical Gang of Four list, any design patterns that you often find misused, misunderstood or overused (other than the highly debated Singleton)? In other words, is there a design pattern you would advise to think twice before using? (And why?)
推荐答案
单例模式..测试时,全局状态通常会导致问题
The singleton pattern ..global state often leads to problems when testing
任何依赖于单例的代码都变得越来越难以测试,因为这种依赖关系不容易被嘲笑.
Any code depending on the singleton gets harder and harder to test because that dependency isn't easily mocked..
这篇关于误用的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!