随笔分类 -  设计模式

设计模式
摘要:Editor's note: This article refers to the Java Memory Model before it was revised for Java 5.0; statements about memory ordering may no longer be correct. However, the double-checked locking idiom is still broken under the new memory model. For more information on the memory model in Java 5.0, s 阅读全文
posted @ 2012-07-16 14:21 腾云生 阅读(231) 评论(0) 推荐(0)
摘要:状态模式状态模式:允许对象在内部状态改变时改变它的行为,对象看起来好像修改了它的类。要点:1. 策略模式和状态模式是双胞胎,它们有相同的类图,但是它们的意图不同。策略模式是围绕可以互换的算法来成功创建业务的,然而状态模式是通过改变对象内部的状态来帮助对象控制自己的行为.2. Context将与状态相关的操作委托给当前的Concrete State对象处理。3. Context可将自身作为一个参数传递给处理该请求的状态对象。这使得状态对象在必要时可访问Context。4. Context或Concrete State类都可决定哪个状态是另外哪一个的后继者,以及是在何种条件下进行状态转换。也就是说 阅读全文
posted @ 2012-05-14 14:06 腾云生 阅读(216) 评论(0) 推荐(0)