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

网站快速排名优化高级网络技术工程师

网站快速排名优化,高级网络技术工程师,盐城 网站开发,wordpress标签关联享元模式 享元模式#xff08;Flyweight Pattern#xff09;又称为轻量模式#xff0c;是对象池的一种实现。类似于线程池#xff0c;线程池可以避免不停的创建和销毁多个对象#xff0c;销毁性能。提供了减少对象数量从而改善应用所需的对象结构的方式。其宗旨是共享细粒…享元模式 享元模式Flyweight Pattern又称为轻量模式是对象池的一种实现。类似于线程池线程池可以避免不停的创建和销毁多个对象销毁性能。提供了减少对象数量从而改善应用所需的对象结构的方式。其宗旨是共享细粒度对象将多个对同一对象的访问集中起来不必为每个访问者创建一个单独的对象以此来降低内存的消耗属于结构型模式。 应用场景 常常应用于系统底层的开发以便解决系统的性能问题。系统有大量相似对象需要缓存池的场景。 利用缓存机制实现享元模式  import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap;interface ITicket{void showInfo(String bunk); }class TrainTicket implements ITicket{private String from;private String to;private int price;public TrainTicket(String from, String to) {this.from from;this.to to;}Overridepublic void showInfo(String bunk) {this.price new Random().nextInt(500);System.out.println(String.format(%s-%s: %s价格: %s 元,this.from,this.to,bunk,this.price));} }class TicketFactory{private static MapString,ITicket sTicketPool new ConcurrentHashMap();public static ITicket queryTicket(String from, String to){String key from - to;if(TicketFactory.sTicketPool.containsKey(key)){System.out.println(使用缓存 key);return TicketFactory.sTicketPool.get(key);}System.out.println(首次查询创建对象 key);ITicket ticket new TrainTicket(from, to);TicketFactory.sTicketPool.put(key,ticket);return ticket;}} JDK中Integer类型使用了享元模式例如。在Java中-128到127之间的数据在int范围类是直接从缓存中取值的。 public class Test {public static void main(String[] args) {Integer a Integer.valueOf(100);Integer b 100;Integer c Integer.valueOf(1000);Integer d 1000;System.out.println(ab); //trueSystem.out.println(bd); //false} } 组合模式  组合模式Composite Pattern也称为整体-部分模式它的宗旨是通过将单个对象和组合对象用相同的接口进行表示使得客户对单个对象和组合对象的使用具有一致性属于结构型模式。 组合关系和聚合关系的区别 组合关系一只狗可以生多只小狗但每只小狗只有一个妈妈具有相同的生命周期。聚合关系一个老师有很多学生但每个学生又有多个老师具有不同的生命周期。 透明组合模式的写法透明组合模式把所有的公共方法都定义在Component中这样做的好处是客户端无需分辨是叶子节点和树枝节点它们具备完全一致性的接口缺点是叶子节点得到一些它所不需要的方法这与设计模式 接口隔离相违背。 import lombok.Data;import java.util.ArrayList; import java.util.List;abstract class CourseComponent{public void addChild(CourseComponent catalogComponent){throw new UnsupportedOperationException(不支持添加操作);}public void removeChild(CourseComponent catalogComponent){throw new UnsupportedOperationException(不支持删除操作);}public String getName(CourseComponent catalogComponent){throw new UnsupportedOperationException(不支持获取名称操作);}public double getPrice(CourseComponent catalogComponent){throw new UnsupportedOperationException(不支持获取价格操作);}public void print(){throw new UnsupportedOperationException(不支持打印操作);} }Data class Course extends CourseComponent{private String name;private double price;public Course(String name, double price) {this.name name;this.price price;}Overridepublic void print() {System.out.println(name ( price 元));} }class CoursePackage extends CourseComponent{private ListCourseComponent items new ArrayList();private String name;private Integer level;public CoursePackage(String name, Integer level) {this.name name;this.level level;}Overridepublic void addChild(CourseComponent catalogComponent) {items.add(catalogComponent);}Overridepublic String getName(CourseComponent catalogComponent) {return this.name;}Overridepublic void removeChild(CourseComponent catalogComponent) {items.remove(catalogComponent);}Overridepublic void print() {System.out.println(this.name);for (CourseComponent catalogComponent : items){if(this.level ! null){for(int i0;ithis.level;i){System.out.print( );}for(int i0;ithis.level;i){System.out.print(-);}}catalogComponent.print();}} }public class Test {public static void main(String[] args) {System.out.println(透明组合模式);CourseComponent javaBase new Course(Java入门,8200);CourseComponent ai new Course(人工智能,5000);CourseComponent packageCourse new CoursePackage(Java架构师,2);CourseComponent design new Course(设计模式,1500);packageCourse.addChild(design);CourseComponent catalog new CoursePackage(课程主目录,1);catalog.addChild(javaBase);catalog.addChild(ai);catalog.addChild(packageCourse);catalog.print();} }安全组合模式的写法好处是接口定义职责清晰符合设计模式单一职责原则和接口隔离原则缺点是客户需要区分树枝节点和叶子节点客户端无法依赖抽象违背了设计模式依赖倒置原则。 import lombok.Data;import java.util.ArrayList; import java.util.List;abstract class CourseComponent{public void print(){throw new UnsupportedOperationException(不支持打印操作);} }Data class Course extends CourseComponent{private String name;private double price;public Course(String name, double price) {this.name name;this.price price;}Overridepublic void print() {System.out.println(name ( price 元));} }class CoursePackage extends CourseComponent{private ListCourseComponent items new ArrayList();private String name;private Integer level;public CoursePackage(String name, Integer level) {this.name name;this.level level;}public void addChild(CourseComponent catalogComponent) {items.add(catalogComponent);}public String getName(CourseComponent catalogComponent) {return this.name;}public void removeChild(CourseComponent catalogComponent) {items.remove(catalogComponent);}Overridepublic void print() {System.out.println(this.name);for (CourseComponent catalogComponent : items){if(this.level ! null){for(int i0;ithis.level;i){System.out.print( );}for(int i0;ithis.level;i){System.out.print(-);}}catalogComponent.print();}} }public class Test {public static void main(String[] args) {System.out.println(透明组合模式);CourseComponent javaBase new Course(Java入门,8200);CourseComponent ai new Course(人工智能,5000);CoursePackage packageCourse new CoursePackage(Java架构师,2);CourseComponent design new Course(设计模式,1500);packageCourse.addChild(design);CoursePackage catalog new CoursePackage(课程主目录,1);catalog.addChild(javaBase);catalog.addChild(ai);catalog.addChild(packageCourse);catalog.print();} }
http://www.hkea.cn/news/14451888/

相关文章:

  • 网站开发拓扑图ppt模板免费下载 素材中国风
  • 天河区建设水务局网站wordpress动漫整站
  • 顺德网站优化公司做兼职的网站有哪些工作内容
  • 用自己的名字做网站域名免费家装设计效果图
  • 手机 pc网站开发价格兰州seo
  • 建设银行论坛网站企业网站的设计与实现
  • 免费做网站怎么做网站ppt制作模板免费下载
  • 德阳网站建设优化网站推广方案整理
  • 淘宝的好券网站怎么做马鞍山网站建设推广
  • 网站建设管理自查报告淘宝优惠网站怎么做
  • 新乡做网站哪家好怎么看网站是什么语言做的后台
  • 民宿设计网站大全厦门网站建站
  • 深圳做网站哪家好wordpress自带重定向
  • 工程建设科学技术奖申报网站电商网课
  • wordpress文章商品导购网站seo关键词排名查询
  • 贸易公司网站建设随意设计一个网站
  • 制作网站基本步骤用淘宝做公司网站
  • 实现网站计划书rails开发的网站开发
  • 深圳做企业网站个人网站模板html免费
  • 企业为什么要做手机网站个人社保缴费app下载
  • 怎么介绍自己做的电影网站网站建设必须要服务器吗
  • 广西城乡建设名网站代理网络游戏需要什么手续
  • 怎么做视频解析的网站html基础菜鸟教程
  • 传统网站与营销型网站做设计应该看哪些网站
  • 建建设网站的网站开发哪家公司口碑好
  • 基金管理公司司网站建设要求免费网站后台管理系统
  • 网站建设定制开发服务wordpress 中文 chm
  • 许昌北京网站建设专业做医院网站建设
  • 做排行的网站长春网架公司
  • 莱芜招聘的网站鞍山网站建设优化