附录2.生成器模式
PART1. 概念示例
1.1 背景故事
1.2 房屋结构体
package pattern
// House 房屋结构体 即最终对外提供的产品
type House struct {
windowType string // windowType 窗户类型
doorType string // doorType 门的类型
floor int // floor 房屋楼层数
}
// GetWindowType 本方法用于获取房屋的窗户类型
func (h House) GetWindowType() string {
return h.windowType
}
// GetDoorType 本方法用于获取房屋的门的类型
func (h House) GetDoorType() string {
return h.doorType
}
// GetFloor 本方法用于获取房屋的楼层数
func (h House) GetFloor() int {
return h.floor
}1.3 生成器接口
1.4 普通房屋生成器
1.5 冰屋生成器
1.6 管理者结构体
1.7 提供对外暴露的创建具体生成器的方法
1.8 客户端创建房屋
PART2. 示例相关UML

PART3. 生成器模式工作流程

PART4. 生成器模式使用场景
PART5. 生成器模式的优缺点
5.1 优点
5.2 缺点
Last updated