文档介绍:软件设计模式ch6
(三) 厂商类
二、对象村餐厅
餐厅的交互
餐厅的角色和职责
(一)
(二)
从餐厅到命令模式
(三)
(一) 餐厅的交互
(二) 餐厅的角色和职责nd
(五) 使用状态实现撤销
要支持撤销,需要修改遥控器类
(五) 使用状态实现撤销
(续)
(五) 使用状态实现撤销
测试
(五) 使用状态实现撤销
RUN
(五) 使用状态实现撤销
通常,实现撤销,需要记录状态
(五) 使用状态实现撤销
CeilingFan
(五) 使用状态实现撤销
CeilingFan(续)
(五) 使用状态实现撤销
CeilingFan命令
(五) 使用状态实现撤销
CeilingFan命令(续)
(五) 使用状态实现撤销
准备测试
(五) 使用状态实现撤销
准备测试(续)
(五) 使用状态实现撤销
RUN
(五) 使用状态实现撤销
五、使用宏命令
每个遥控器都需要Party模式
使用宏命令
(一)
(二)
当遥控器控制不同的设备呢?
(一) 每个遥控器都需要Party模式
(一) 每个遥控器都需要Party模式
当遥控器控制不同的设备呢?
(一) 每个遥控器都需要Party模式
(二) 使用宏命令
创建宏命令集合
(二) 使用宏命令
(二) 使用宏命令
创建两个数组
(二) 使用宏命令
指定宏命令到按钮
(二) 使用宏命令
最后,测试
(二) 使用宏命令
RUN
六、命令模式的更多用途
队列请求
日志请求
(一)
(二)
(一) 队列请求
(二) 日志请求
七、总结
Abstraction
Encapsulation
Polymorphism
Inheritance
Encapsulate what varies.
Favor composition over inheritence.
Program to interfaces, not implementations.
Strategy - defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
总结
OO Basics
OO Principles
OO Patterns
1
Observer - defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically
总结
OO Patterns
Strive for loosely coupled designs between objects that interact.
OO Principles
2
Decorator - Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
总结
OO Patterns
Classes should be open for extension but closed for modification.
OO Principles
3
Abstract Factory - Provide an interface for creating families of related or depedent objects without specifying their concrete classes.
Factory Method - Define an interfa