设计模式之原型模式
来源:互联网 发布:php 判断大小 编辑:程序博客网 时间:2024/06/18 07:05
背景
期末作业系列之设计模式
原型模式示例
实现clonable接口并重写clone()方法的类:
public class SonDellOffice implements Cloneable{ private String officeNameString ="dell子公司"; public SonDellOffice(){ } public String getOfficeNameString() { return officeNameString; } public void setOfficeNameString(String officeNameString) { this.officeNameString = officeNameString; } @Override public SonDellOffice clone() { SonDellOffice sonDellOffice = null; try { sonDellOffice = (SonDellOffice)super.clone(); } catch (CloneNotSupportedException e) { // TODO: handle exception e.printStackTrace(); } return sonDellOffice; }}
Main客户端调用
public class client { public static void main(String[] args) { DellHeadOffice dellHeadOffice = DellHeadOffice.getDellHeadOffice(); dellHeadOffice.saySomething(); SonDellOffice sonDellOffice = new SonDellOffice(); for(int i=1;i<=3;i++){ SonDellOffice cloneSonDellOffice = sonDellOffice.clone(); cloneSonDellOffice.setOfficeNameString(cloneSonDellOffice.getOfficeNameString()+i); System.out.println(cloneSonDellOffice.getOfficeNameString()); } ProductSeller productSeller = new EShopProxy(); productSeller.sellProduct(); }}
阅读全文
0 0
- 设计模式之原型
- 设计模式之原型
- 设计模式 之 原型
- 设计模式之原型
- 设计模式之原型
- 设计模式之原型模式
- 设计模式之原型模式
- 设计模式之-原型模式
- 设计模式之 原型模式
- 设计模式之原型模式
- 设计模式之原型模式
- 设计模式之原型模式
- 设计模式之原型模式
- 设计模式之原型模式
- 设计模式之--原型模式
- 设计模式之原型模式
- 设计模式之原型模式
- 设计模式之原型模式
- Aptana插件版Zip包下载方法
- Java基础之模拟购物系统案例
- 没有树莓派显示器,键盘,鼠标,串口, 树莓派怎么无线上网?
- C++通过特定时间戳转日期
- 【angular】解决跨域问题
- 设计模式之原型模式
- python---局域网扫描简化版、平台判断、平台创建文件、文件操作、range、数字列表转成字符列表、不同平台ping操作
- 使用Vegan包进行生态学数据排序分析的学习(一)
- Intellij IDEA创建maven项目无java文件问题
- redis学习笔记六(多机多节点集群)
- C++解决 倒水算法
- Android开发 camera被占用的问题
- Linux进程通信(二)
- Python机器学习(一)数据分析工具Pandas