设计模式
2016-03-30 10:39:36 0 举报
常用的设计模式
作者其他创作
大纲/内容
ComponentC
单例模式
Proxy
- mImpl:IComponent
+ Proxy()+ operation()- doSomething()
Strategy1
- mType:Type1
+ oparation(params)
swith(conditoin){case 1: return new ComponentA():case 2: return new ComponentB():case 3: return new ComponentC();...}
Triangle
+draw()
ComponentImpl
+ operation()
AdapterA
-mLibraryClass:LibraryClass
+ AdapterA()+ operation()
IDrawProgram
装饰者模式
Command
-mAction:Action
+execute()
IComponent
策略模式
外观模式
ObserverC
FctoryB
Decorator
+ setComponentImpl(impl:IComponent)+ operation()- doSomething()
IFactory
+ createComponentA():return IComponentA+ createComponentB():return IComponentB
适配器模式
Client
getProduct()
ComponentA
ClientA
ObserverB
Factory
+static getComponent(condition):return IComponent
SingleHolder
+sHolder:static final Singleton
IComponentB
FactoryA
new Product.Builder() .setType1(type1) .setType2(type2) .build()
Singleton
+ getSingleInstance():return Singleton
FactoryB
ComponentB
Product
- mType1:Type1- mType2:Type2
+setType1(type:Type1)+setType2(type:Type2)
mImpl = new ComponentImpl();
first():second():third():
ConcreteClass2
# third()
命令模式
简单工厂模式
return SingleHolder.sHolder
DPB
ComponentA1
FactoryC
ObserverA
MyProject
ComponentB1
Builder
+setType1(type:Type1):return Builder+setType2(type:Type2):return Builder+build():return Product
Adapter
//change state and thennotigyAll()
ClientB
Action
+actionA()+actionB()
ConcreteClass1
# first()-doSomethingElse()
AbsTemplate
# first()# second()# third()+ final operation()
建造者模式
-mCmdList:List
+addCommand(cmd:Command)+notify()
工厂模式
if(...)mImpl.operation();elsedoSomething();
IStrategy
FctoryA
ComponentA2
CommandB
Retangle
doSomethingElse()super.first()
+ createComponent():return IComponent
doSomething();mImpl.operation();
观察者模式
LibraryClass
ComponentB2
桥接模式
AbsShape
-mProgram:IDrawProgram
+setProgram(program:IDrawProgram)+draw()
//do something else and thenproduct = new Product();product.setType1(mType1);product.setType2(mType2);return product;
IComponentA
抽象工厂模式
mLibraryClass = new LibraryClass();
代理模式
Observable
- mList:ListWeakReference
+addObserver(ob:Observer)+removeObserver(ob:Observer)+notifyAll()+changeState(newState)
Facade
Strategy2
- mType:Type2
DPA
模板方法模式
CommandA
User
- mStrategy:IStrategy
+ setStrategy(interface: IStrategy)+ doSomething()
mLibraryClass.method()
CommandC
Observer
0 条评论
下一页