知识卡片
状态模式的扩展代价
把状态行为分到各自实现,可以在同处查看发布状态的所有规则,避免每个 Post 方法都重复按状态匹配。状态间仍因转移而耦合,插入定时发布状态时,待审核状态要改目的地。动作数量增多还会重复外层委托及某些无效动作实现。选择时可分别估计新增状态和新增动作的频率。
相关卡片 [[状态对象管理行为]]、[[以类型约束状态转移]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 面向对象编程特性 Requesting a Review Changes the Post’s State · 查看原书依据
One downside of the state pattern is that, because the states implement the transitions between states, some of the states are coupled to each other. If we add another state between PendingReview and Published, such as Scheduled, we would have to change the code in PendingReview to transition to Scheduled instead.
参考来源
- 位置:《The Rust Programming Language(第2版)》第17章 面向对象编程特性(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c17.xhtml`,块 0169)
- 结论依据:原文以插入 Scheduled 必须改 PendingReview 的转移为例,指出行为集中之后仍有转移依赖。
- 原始内容:One downside of the state pattern is that, because the states implement the transitions between states, some of the states are coupled to each other. If we add another state between PendingReview and Published, such as Scheduled, we would have to change the code in PendingReview to transition to Scheduled instead.