当前位置: 首页 > news >正文

通江县城乡建设局门户网站产品软文模板

通江县城乡建设局门户网站,产品软文模板,上海网站建设开发电话,有一个做5s壁纸的网站文章目录一、引入二、代理模式,Prototype Pattern2.1 Intent 意图2.2 Applicability 适用性2.3 类图2.4 应用实例:使用下划线或消息框展示字符串2.4 应用实例:JDK java.lang.Object java.lang.Cloneable一、引入 二、代理模式,Pr…

文章目录

      • 一、引入
      • 二、代理模式,Prototype Pattern
        • 2.1 Intent 意图
        • 2.2 Applicability 适用性
        • 2.3 类图
        • 2.4 应用实例:使用下划线或消息框展示字符串
        • 2.4 应用实例:JDK java.lang.Object java.lang.Cloneable

一、引入

二、代理模式,Prototype Pattern

代理模式实现了一个原型接口用于创建当前对象的克隆。

2.1 Intent 意图

  • Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. 使用原型实例指定要创建的对象类型,并通过克隆此原型来创建新对象

2.2 Applicability 适用性

  • When a system should be independent of how its products are created, composed, and represented. 当一个系统应该独立于它的产品创建,构成和表示时
  • When the classes to instantiate are specified at run-time, for example, by dynamic loading. 当要实例化的类是在运行时刻指定时,例如,通过动态装载.
  • To avoid building a class hierarchy of factories that parallels the class hierarchy of products. 为了避免创建一个与产品类层次平行的工厂类层次时. (工厂模式介绍)
  • When instances of a class can have one of only a few different combinations of state. 当一个类的实例只能有几个不同状态组合中的一种时.

2.3 类图

在这里插入图片描述

  • Prototype: Declares an interface for cloning itself. 声明一个用于克隆自身的接口
  • ConcretePrototype: Implements an operation for cloning itself. 实现一个克隆自身的操作

2.4 应用实例:使用下划线或消息框展示字符串

To show a string with underline or message box:
在这里插入图片描述

  • Conventionally, we have to design three different classes to show a string with underline or message box
  • However, we will design too many classes to show different underline or message box styles

  • Prototype:
public interface Product extends Cloneable {public abstract void use(String s);public abstract Product createClone();
}
public class MessageBox implements Product {private char decochar;public MessageBox(char decochar) {this.decochar = decochar;}public void use(String s) {int length = s.getBytes().length;for (int i = 0; i < length + 4; i++) {System.out.print(decochar);}System.out.println("");System.out.println(decochar + " "  + s + " " + decochar);for (int i = 0; i < length + 4; i++) {System.out.print(decochar);}System.out.println("");}public Product clone() {Product p = null;try {p = (Product) super.clone();} catch (CloneNotSupportedException e) {e.printStackTrace();}return p;}
}
public class UnderlinePen implements Product {private char ulchar;public UnderlinePen(char ulchar) {this.ulchar = ulchar;}public void use(String s) {int length = s.getBytes().length;System.out.println("\""  + s + "\"");System.out.print(" ");for (int i = 0; i < length; i++) {System.out.print(ulchar);}System.out.println("");}public Product clone() {Product p = null;try {p = (Product) super.clone();} catch (CloneNotSupportedException e) {e.printStackTrace();}return p;}
}
  • Manager:
public class Manager {private HashMap showcase = new HashMap<String, Product>();public void register(String name, Product proto) {showcase.put(name, proto);}public Product create(String protoname) {Product p = (Product) showcase.get(protoname);return p.clone();}
}
  • ClientDemo
public class Main {public static void main(String[] args) {// 准备Manager manager = new Manager();UnderlinePen upen = new UnderlinePen('~');MessageBox mbox = new MessageBox('*');MessageBox sbox = new MessageBox('/');manager.register("strong message", upen);manager.register("warning box", mbox);manager.register("slash box", sbox);// 生成Product p1 = manager.create("strong message");p1.use("Hello, world.");Product p2 = manager.create("warning box");p2.use("Hello, world.");Product p3 = manager.create("slash box");p3.use("Hello, world.");}
}

在这里插入图片描述

2.4 应用实例:JDK java.lang.Object java.lang.Cloneable

java.lang.Object
在这里插入图片描述

http://www.ds6.com.cn/news/43589.html

相关文章:

  • 企业做网站的发票会计分录客服外包平台
  • 免费做微信请帖的网站济南网站运营公司
  • 北京网站建设产品介绍seo外包公司多吗
  • 网站建设推广 seo百度关键词搜索引擎排名优化
  • 中期通网站建设2024年的新闻
  • 湘潭做网站口碑好磐石网络代写文章多少钱
  • 国内吃瓜爆料黑料网曝门湖南关键词优化品牌价格
  • 浦东网站建设宁波超值关键词优化
  • 重庆市建设工程信息网首页seo排名优化收费
  • 淘宝联盟 网站建设 内容少推广的几种方式
  • 宁波市住房和城乡建设厅网站西安seo公司哪家好
  • 国外网站国内做二维码推广网站大全
  • 做金馆长网站网站东莞网络优化公司
  • 丹东做网站的公司搜索引擎优化seo专员
  • 用帝国cms做企业网站php免费开源crm系统
  • 做网站推广合同长沙seo网站优化
  • 怎么用ppt做网站公司网站建设哪个好
  • 中国建设银行嵊州市支行网站seo是什么技术
  • wordpress菜单图教武汉seo学徒
  • .cf域名解析其他网站上海百度公司地址
  • 鲁棒导航seo团队管理系统
  • 百度贴吧论坛宁波seo整站优化
  • 如何用网页制作网站江苏网络推广公司
  • 自助制作网站百度竞价排名广告定价
  • 泰安建设工程招聘信息网站阿里指数在哪里看
  • java实现大型门户网站开发经验怎么做好网络推广销售
  • 瓜子二手车网站开发北京做的好的seo公司
  • 建设 展示型企业网站360线上推广
  • wordpress迁移到laravelseo爱站网
  • 青岛做网站哪家好广州企业推广