Design pattern:Adapter 设计模式:适配器

Categories: Java; Tagged with: ; @ July 19th, 2012 11:04

Adapter pattern(Wrapper pattern), is a design pattern that allows classes to work together, those classes can not work normally because they have incompatible interface.
For example, you travel from US to China, you need to use an adapter so that you charger can work, because they have different standard.

There are two types, one is Class level, and the other is Object(Instance) level.
Class Adapter pattern:

“The adapter is created by implementing or inheriting both the interface that is expected and the interface that is pre-existing. It is typical for the expected interface to be created as a pure interface class, especially in languages such as Java that do not support multiple inheritance

(http://en.wikipedia.org/wiki/Adapter_pattern)

Object Adapter pattern

Adapter contains an instance of the class it wraps, so that the adapter can delegate the request to warped instance.

 

设计模式之策略模式: Strategy Design Pattern

Categories: Flex; Tagged with: ; @ July 17th, 2011 17:59

适用情景:   假如有一组相关的算法, 客户需要从中动态选择一个来使用. 譬如: 学校中的新生分班, 有按照成绩分班, 按照性别分班, 按照住宿类型分班等等.  (当然实际情况中的分班考虑因素会更复杂一些)

最简单的方法是一个Method, 通过判断类型进行相应操作. 但这样做的是这个Method会巨大无比, 不易维护. 因此我们可使用Strategy模式, 会多一些Interface或Class, 但会降低耦合, 拥有更佳的可扩展性.

_SHUPZTTF4MMN_D7DT7TBX0
(ActionScript)

负责进行分班的主体类包含IClassEnrollStrategy的一个Instance, 对于这个Instance可以使用以下方式注入:

1. 使用Constructor注入到ClassEnroll中, 可在ClassEnroll中增加一个Constructor:
ClassEnroll(strategy:IClassEnrollStrategy)

2. 使用Setter注入. ClassEnroll中对strategy的Setter方法:
setStrategy(strategy:IClassEnrollStrateStrategy)

3. 在ClassEnroll使用工厂模式创建IClassEnrollStrategy实例.

<<企业应用架构模式[影印版]>>笔记整理

Categories: Development Notes; Tagged with: ; @ November 18th, 2008 23:20

书很好, 层次清晰, 语言简练. 只是我英语太差, 读的稍稍有些吃力. 把自己理解的记录一下, 即便是错误的, 也先记录下来.

1. Domain

这个是最困惑我的一个词语.
一般来讲, Domain指一个领域, 譬如Product, Student. 用户的需求一般为Domain, 用户需求中的名词多为Class, 用户需求的限制多为逻辑.

2.Unit of Work

Unit of Work有两个要素:
1. 有多个Work

2. 多个Work同一个Transation, 全部成功或全部失败.

3. Indentity Map

将从DataBase中读取出来的对象放在一个Map中, 需要使用对象时, 先检查Map中是否存在, 不存在的情况下才去从DataBase读取.

4. Qury Object

用Object来代替SQL, EJB SQL语句, 可以增加Cache以及时间控制等

5. MetaData Mapping

Knowledge Level’s Knowledge Level.

例如, 一个Table中的某个Record 是一个 Operation Level, 则对应Column为该Record的Knowledge Level, 而该Column的属性描述,则为MetaData.

6.Service Layer

通过使用Service Layer来划分软件层次, 达到降低耦合的要求.

每个Layer不必提供过多服务, 而应当提供恰当的服务, 以降低开发,维护的复杂度. 类似与日常生活中组织机构的管理.一般来说,可以以此通过Project, Source Folder, Package, Class来划分Service Layer.

…..

这本书太高深了, 只能高山仰止了…

Flex Singleton Pattern—-Flex中的单例模式

Categories: Flex; Tagged with: ; @ October 1st, 2008 0:49

(more…)



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.