当前位置:网站首页>【DesignMode】原型模式(prototype pattern)
【DesignMode】原型模式(prototype pattern)
2022-07-02 03:25:00 【weixin_43224306】
基本介绍:
原型模式(Prototype 模式)是指:用原型实例指定创建对象的种类,并且通过拷贝这些原型,创建新的对象
原型模式是一种创建型设计模式,允许一个对象再创建另外一个可定制的对象,无需知道如何创建的细节
工作原理是:通过将一个原型对象传给那个要发动创建的对象,这个要发动创建的对象通过请求原型对象拷贝它们自己来实施创建,即 对象.clone()
1.克隆羊问题
现在有一只羊 tom,姓名为: tom, 年龄为:1,颜色为:白色,请编写程序创建和 tom 羊 属性完全相同的 10
只羊。
2.传统方式解决克隆羊问题
类图:
代码:
package com.mumu.prototype;
public class
边栏推荐
- In depth analysis of C language - variable error prone knowledge points # dry goods inventory #
- 寻找重复数[抽象二分/快慢指针/二进制枚举]
- Detailed explanation of ThreadLocal
- C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
- KL divergence is a valuable article
- Continuous assignment of Verilog procedure
- Verilog 状态机
- 终日乾乾,夕惕若厉
- [database]jdbc
- MySQL advanced (Advanced) SQL statement (II)
猜你喜欢
数据传输中的成帧
Halcon image rectification
MSI announced that its motherboard products will cancel all paper accessories
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Verilog 避免 Latch
MySQL advanced (Advanced) SQL statement (II)
[HCIA continuous update] overview of dynamic routing protocol
[JS reverse series] analysis of a customs publicity platform
Verilog timing control
PY3, PIP appears when installing the library, warning: ignoring invalid distribution -ip
随机推荐
SAML2.0 笔记(一)
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
MySQL advanced (Advanced) SQL statement (II)
Go execute shell command
Verilog reg register, vector, integer, real, time register
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
< job search> process and signal
Discrimination between sap Hana, s/4hana and SAP BTP
Eight steps of agile development process
JS generate random numbers
32, 64, 128 bit system
On redis (II) -- cluster version
This article describes the step-by-step process of starting the NFT platform project
数据传输中的成帧
C shallow copy and deep copy
Qualcomm platform wifi-- WPA_ supplicant issue
[HCIA continuous update] overview of dynamic routing protocol
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
venn图取交集
Delphi xe10.4 installing alphacontrols15.12