学习高校课程-软件设计模式-备忘录模式和观察者模式(lec11)

Memento: Problem

Example: supporting undo in a text editor app
Problem 1: private fields cannot be accessed
Problem 2: when fields are made public, refactoring would be problematic
Problem 3: the fields of the snapshot class need to be public, exposing all the editor’s states
示例:在文本编辑器应用程序中支持撤消
问题一:私有字段无法访问
问题2:当字段公开时,重构会出现问题
问题3:快照类的字段需要是public的,暴露所有的编辑的状态

Memento: Solution

Essence of the problems: broken encapsulation
Memento: delegating the creation of state snapshots to the actual owner of the state – the originator object
Storing the copy of state in a special object: memento
问题本质:破损封装
备忘录:将状态快照的创建委托给状态的实际所有者——发起者对象
将状态副本存储在特殊对象中:备忘录

Observer: Problem

Two types of objects: Customer and Store
The customer is interested in a particular product which should become available soon
• Problem 1: the customer visits the store frequently and checks product availability
• Problem 2: the store sends tons of emails to all customers each time
a new product becomes available

两种类型的对象:客户和商店
客户对某种即将上市的特定产品感兴趣
问题 1 :顾客经常到店检查商品库存情况
问题 2:每次有新产品上市时,商店都会向所有顾客发送大量电子邮件

Observer: Solution

posted @   Mephostopheles  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示