Head First设计模式C++实现-Factory模式
来源:互联网 发布:telnet 端口号 编辑:程序博客网 时间:2024/06/06 03:18
定义:
工厂方法模式定义了一个创建对象的接口,但由子类决定要实例化的类是哪一个。工厂方法让类把实例化推迟到子类。
作用:
将创建对象的代码集中在一个对象或方法中,可以避免代码中的重复,并且更方便以后的维护。这也意为着客户在实例化对象时,只会依赖于接口,而不是具体类。这遵循了实现针对接口编程,而不针对实现编程的原则。可以让代码更具有弹性,可以应对未来的扩展。
UML结构图如下:
实现代码:
程序输出:
Preparing NY Style Sauce and Cheese Pizza
Tossing Thin Crust Dough
Adding Martinara Sauce
Adding toppings:
Greated Reggiano Cheese
Bake for 25 minutes at 350
Cutting the pizza into diagonal slices
Place pizza in official PizzaStore box
Ethan ordered a NY Style Sauce and Cheese Pizza
Preparing Chicago Style Deep Dish Cheese Pizza
Tossing Extra Thick Crust Dough
Adding Plum Tomato Sauce
Adding toppings:
Shredded Mozzarella Cheese
Bake for 25 minutes at 350
Cutting the pizza into square slices
Place pizza in official PizzaStore box
Joel ordered a Chicago Style Deep Dish Cheese Pizza
请按任意键继续. . .
- Head First设计模式C++实现-Factory模式
- Head First 设计模式之工厂模式(Factory Pattern)
- Head First 设计模式 (四) 工厂模式(factory pattern) C++实现
- Head First设计模式C++实现--第四章:工厂(Factory)模式
- Head First 设计模式 Design Pattern 3-4 Decorator, Factory
- Head First 设计模式
- Head-first设计模式
- head first 设计模式
- head first 设计模式
- Head First 设计模式
- 《Head First 设计模式》
- Head First设计模式
- Head First《设计模式》
- 《Head First设计模式》
- Head First设计模式
- Head First 设计模式 C++实现
- Head First 设计模式—Python实现
- head first设计模式cpp实现
- rend
- 替换(replace)
- dsgses
- 增量模型优缺点
- 前景文档模板
- Head First设计模式C++实现-Factory模式
- 筛法求小于等于整数n的所有质数
- 架构层面的需求分析
- 保留空间(reserve)
- 架构层次的用例文档编写
- ArcObjects学习
- 成功软件架构的品质
- IP地址 网段的划分
- 成功架构设计的关键要素