当前位置:网站首页>【DesignMode】工厂模式 (factory pattern)
【DesignMode】工厂模式 (factory pattern)
2022-06-30 18:02:00 【weixin_43224306】
1. 简单工厂模式
简单工厂模式是属于创建型模式,是工厂模式的一种。简单工厂模式是由一个工厂对象决定创建出哪一种产品
类的实例。简单工厂模式是工厂模式家族中最简单实用的模式简单工厂模式:定义了一个创建对象的类,由这个类来封装实例化对象的行为(代码)
在软件开发中,当我们会用到大量的创建某种、某类或者某批对象时,就会使用到工厂模式.
1.1看一个具体的需求
看一个披萨的项目:要便于披萨种类的扩展,要便于维护
披萨的种类很多(比如 GreekPizz、CheesePizz 等)
披萨的制作有 prepare,bake, cut, box
完成披萨店订购功能。
1.2使用传统的方式来完成
类图:
代码:
//public class OrderPizza {
// 构造器
// public OrderPizza() {
// Pizza pizza = null;
<
边栏推荐
- MySQL function to get the full path
- MySQL download and installation tutorial
- Personally test the size of flutter after packaging APK, quite satisfied
- VMware16安装Win11虚拟机(最全步骤+踩坑)
- 年复一年,为什么打破数据孤岛还是企业发展的首要任务
- [Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
- mysql 递归
- sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户
- German agbb VOC hazardous substances test
- NFT technology for gamefi chain game system development
猜你喜欢
Business Intelligence BI and business management decision-making thinking 4: business cost analysis
Leader: who can use redis expired monitoring to close orders and get out of here!
sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户
VMware16安装Win11虚拟机(最全步骤+踩坑)
Full recharge, im+rtc+x full communication service "feedback season" starts
Construction and practice of full stack code test coverage and use case discovery system
Opencv data type code table dtype
Video content production and consumption innovation
Teach you to quickly set up a live studio in 30 minutes
年复一年,为什么打破数据孤岛还是企业发展的首要任务
随机推荐
sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户
France a+ France VOC label highest environmental protection level
嵌入式软件开发新趋势:DevOps
Vs common shortcut key commands
Influence and requirements of different manufacturing processes on the pad on PCB
opencv数据类型代码表 dtype
Kalman filter -- Derivation from Gaussian fusion
Swin-Transformer(2021-08)
Opencv data type code table dtype
Compare the audio librosa library with the Mel spectrogram in the torchaudio library
云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
Redis beginner to master 01
Courage to be hated: Adler's philosophy class: the father of self inspiration
Word -- a solution for word to encounter errors when trying to open a file
浏览器窗口切换激活事件 visibilitychange
全栈代码测试覆盖率及用例发现系统的建设和实践
ArcGIS无插件加载(无偏移)天地图
Personally test the size of flutter after packaging APK, quite satisfied
nats集群部署
Brief introduction of Feature Engineering in machine learning