当前位置:网站首页>Gof23 - prototype mode
Gof23 - prototype mode
2022-06-26 06:15:00 【Kuxiaoya】
Archetypal model :
Archetypal model (Prototype Pattern) Is used to create duplicate objects , At the same time, it can guarantee the performance . This type of design pattern is a creation pattern , It provides the best way to create objects .
This pattern is to implement a prototype interface , This interface is used to create a clone of the current object . When the cost of creating objects directly is high , Then use this mode

The code is as follows :
package prototype.Demo1;
import java.util.Date;
/** * 1、 Implement an interface Cloneable * 2、 Rewrite a method * */
public class Video implements Cloneable {
private String name;
private Date createTime;
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public Video() {
}
public Video(String name, Date createTime) {
this.name = name;
this.createTime = createTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
return "Video{" +
"name='" + name + '\'' +
", createTime=" + createTime +
'}';
}
}
package prototype.Demo1;
import javax.xml.crypto.Data;
import java.util.Date;
/** * client : clone */
public class Bilibli {
public static void main(String[] args) throws CloneNotSupportedException {
// Prototype object
Date date = new Date();
Video v1 = new Video(" Cool little ", date);
System.out.println("v1=>"+v1);
System.out.println("v1=>hash"+v1.hashCode());
// Give Way v2 clone v1
Video v2 = (Video) v1.clone();
System.out.println("v2=>"+v2);
System.out.println("v2=>hash"+v2.hashCode());
}
}

边栏推荐
- Data visualization practice: Experimental Report
- Household accounting procedures (First Edition)
- 【群内问题学期汇总】初学者的部分参考问题
- How to design a good technical scheme
- Spark source code analysis (I): RDD collection data - partition data allocation
- Prometheus和Zabbix的对比
- Use the fast proxy to build your own proxy pool (mom doesn't have to worry about IP being blocked anymore)
- How to select and build a real-time data warehouse scheme
- 数据可视化实战:实验报告
- Message queuing - omnidirectional comparison
猜你喜欢

Cython入门

Data visualization practice: Experimental Report

Logstash——Logstash将数据推送至Redis

Household accounting procedures (First Edition)

Redis multithreading and ACL

【Spark】Spark SQL 字段血缘如何实现

在web页面播放rtsp流视频(webrtc)

GoF23—原型模式

MySQL 索引底层原理
![Selective search for object recognition paper notes [image object segmentation]](/img/cf/d3b08d41083f37c164b26a96b989c9.png)
Selective search for object recognition paper notes [image object segmentation]
随机推荐
How to associate wechat applet QR code to realize two code aggregation
Use the fast proxy to build your own proxy pool (mom doesn't have to worry about IP being blocked anymore)
Thinking skills of technical leaders
Understanding of nil in go language
Tencent's 2022 school recruitment of large factories started with salary, and the general contracting of cabbage is close to 40W!
Class and object learning
Several promotion routines of data governance
Selective Search for Object Recognition 论文笔记【图片目标分割】
Static proxy mode
数据可视化实战:实验报告
Data visualization practice: Data Visualization
[intra group questions semester summary] some reference questions for beginners
Thinking and summary of technical ability
SQL server functions
Lamda expression
Upgrading technology to art
Household accounting procedures (the second edition includes a cycle)
Redis underlying data structure
Redis multithreading and ACL
tf.nn.top_k()