当前位置:网站首页>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());
}
}

边栏推荐
- MySQL 索引底层原理
- Detailed explanation of serial port communication principle 232, 422, 485
- EFK升级到ClickHouse的日志存储实战
- 05. basic data type - Dict
- DPDK——TCP/UDP协议栈服务端实现(二)
- The difference between abstract and interface interface
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
- GoF23—建造者模式
- Redis多线程与ACL
- SSH keygen specifies the path
猜你喜欢

Introduction to canal deployment, principle and use

Five solutions across domains

Ppt template crawler case
![Selective search for object recognition paper notes [image object segmentation]](/img/cf/d3b08d41083f37c164b26a96b989c9.png)
Selective search for object recognition paper notes [image object segmentation]

Evolution history of qunar Bi platform construction

Keepalived to achieve high service availability

Library management system

去哪儿网BI平台建设演进史

GoF23—原型模式

Selective Search for Object Recognition 论文笔记【图片目标分割】
随机推荐
Import / export function implementation
DPDK——TCP/UDP协议栈服务端实现(二)
在web页面播放rtsp流视频(webrtc)
302. 包含全部黑色像素的最小矩形 BFS
跨域的五种解决方案
MySQL-08
The difference between overload method and override method
MySQL-06
volatile应用场景
Architecture design method
C generic speed
Yamaha robot splits visual strings
tf. nn. top_ k()
canal部署、原理和使用介绍
GoF23—建造者模式
University Information Management System
06. talk about the difference and coding between -is and = = again
花生壳内网穿透映射NPM私服问题
Selective search for object recognition paper notes [image object segmentation]
数据治理工作的几种推进套路