学习高校课程-软件设计模式-迭代者模式和中介者模式(lec10)

Iterator: Problem

Collections are one of the most used data types in programming
There should be a way to go through each element of the collection
More traversal algorithms to the collection blurs its primary responsibility
Some algorithms might be tailored for a specific application
The client code may not care about how the elements are stored
集合是编程中最常用的数据类型之一
应该有一种方法来遍历集合中的每个元素
对集合的更多遍历算法模糊了其主要职责
某些算法可能是针对特定应用而定制的
客户端代码可能不关心元素如何存储

Iterator: Solution

Main idea: extract the traversal behavior of a collection into a separate object called an iterator
主要思想:将集合的遍历行为提取到一个单独的对象中,称为迭代器

Mediator: Problem


Elements may interact with each other
Changes to one element may affect others
Elements become harder to reuse
– 元素可能会相互交互 – 对一个元素的更改可能会影响其他元素 – 元素变得更难以重用

Mediator: Solution

Mediator (aka Intermediary or Controller)
中介者(又名中介者或控制者)
– Cease direct communications among components
– Collaborate indirectly by calling a special mediator object
– 停止组件之间的直接通信
– 通过调用特殊的中介对象来间接协作

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