|
此文章由 dalaohu 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 dalaohu 所有!转贴必须注明作者、出处和本声明,并保持内容完整
原帖由 wtf 于 2010-3-19 17:18 发表 
当时我的感触主要是
比如说到Singleton模式,他对这种模式的理解和感触都很深。给出了很多这种模式的好处和不好的地方。比如XX模式,在Agile模式下,多组合作开发的时候,容易出现XX问题,时间久了之后,会产生啥啥 ...
只有吃过Singleton苦头的才会感触很深吧?
Singleton 跟Agile, 多组合作开发有个鸟关系啊, 你到底懂不懂啊?? 如今什么project不是agile, 多组合作开发??
由Pattern而出现问题还要等时间久了才发现?? 我这是服了你了!
要我在面试你是,您把这些话说出来, 我当场就喷饭。可能立马就叫您上鸡玩玩。 哈哈。只能说您对这模式的理解和感触太深刻了。 LOL。。。您那单位的?
说实在的Singleton用那么讨论吗?用在面试是聊半小时吗!! 早有定论了, 尽量不用!
Singletons are very similar to global variables, and are often implemented with global variables, even if they masquerade as class members. Singleton promotes tight coupling between classes!
Nonetheless, singletons have problems similar to globals; e.g., creating dependencies in vastly separated parts of the system, so side effects can appear far afield from their causes. Often singletons are abused by inexperienced programmers who think that the use of the pattern will magically solve all the problems associated with GlobalVariables.
很多junior dev 会到处用Static!!!, static variables, static classes!
DrawBacks of Singleton
It should be noted that this pattern makes unit testing far more difficult, as it introduces global state into an application. It should also be noted that this pattern reduces the potential for parallelism within a program, because access to the singleton in a multi-threaded context must be serialised, i.e. by locking. Advocates of dependency injection would regard this as an anti-pattern, mainly due to its use of private and static methods.
唯一用Singleton 地方是 inside Common project, 你可能会有一些Factory pattern 的module, ie。 Logger, Providers ...etc。 其余所有project tier, Singleton 基本上是禁用的。 它在根本上是和loose coupling, interface driven, test driven those modern programming methodlogies 背道而驰!
张口design pattern, 闭口模式的人是最令人讨厌的。 您究竟开发过些啥啊? 还面试这,面试那, 您这不是耽误人吗!
我见过不少说起那些生僻理论口若悬河的,干出来的活那就一个鸟。
[ 本帖最后由 dalaohu 于 2010-3-21 16:15 编辑 ] |
评分
-
查看全部评分
|