23种设计模式之python实现--Memento模式
2014-04-19 12:58
537 查看
#理解 #Memento模式的关键是不破坏封装 #Originator class Originator: def __init__(self,sta): self.state=sta def SetMemento(self,Mem): self.state=Mem.getState() def CreateMento(self): return Memento(self.state) class Memento: def __init__(self,state): self.SetState(state) def getState(self): return self.state def SetState(self,state): self.state=state if __name__=="__main__": ori=Originator("hello") print ori.state mem=ori.CreateMento() ori.state="world" print ori.state ori.SetMemento(mem) print ori.state
相关文章推荐
- 23种设计模式之python实现--抽象工厂
- 23种设计模式之python实现--Composite模式
- 23种设计模式之python实现--Flyweight模式
- 23种设计模式之python实现--解释器模式
- 23种设计模式之python实现--Prototype模式
- 23种设计模式之python实现--Adapter模式
- 23种设计模式之python实现--State模式
- Python如何实现单例模式?其他23种设计模式python如何实现?
- 23种设计模式之python实现
- 23种设计模式之python实现--单例模式
- 23种设计模式之python实现--builder模式
- 23种设计模式之python实现--visitor模式
- 23种设计模式之python实现--中介者模式
- 23种设计模式之python实现--Template模式
- 23种设计模式之python实现--Facade模式
- 23种设计模式之python实现--command模式
- 23种设计模式之python实现--工厂方法
- 23种设计模式之python实现--Strategy模式
- 23种设计模式之python实现--职责链模式
- 23种设计模式之python实现--Iterator模式