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

网站规划的基本内容有哪些武汉seo首页优化公司

网站规划的基本内容有哪些,武汉seo首页优化公司,做网站安全维护是什么东东,ps怎么做网站首页界面享元模式 享元模式(Flyweight Pattern)又称为轻量模式,是对象池的一种实现。类似于线程池,线程池可以避免不停的创建和销毁多个对象,销毁性能。提供了减少对象数量从而改善应用所需的对象结构的方式。其宗旨是共享细粒…

享元模式

享元模式(Flyweight Pattern)又称为轻量模式,是对象池的一种实现。类似于线程池,线程池可以避免不停的创建和销毁多个对象,销毁性能。提供了减少对象数量从而改善应用所需的对象结构的方式。其宗旨是共享细粒度对象,将多个对同一对象的访问集中起来,不必为每个访问者创建一个单独的对象,以此来降低内存的消耗,属于结构型模式。

应用场景:

  1. 常常应用于系统底层的开发,以便解决系统的性能问题。
  2. 系统有大量相似对象,需要缓存池的场景。

利用缓存机制实现享元模式: 

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 Map<String,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(a==b); //trueSystem.out.println(b==d); //false}
}

组合模式 

组合模式(Composite Pattern)也称为整体-部分模式,它的宗旨是通过将单个对象和组合对象用相同的接口进行表示,使得客户对单个对象和组合对象的使用具有一致性,属于结构型模式。

组合关系和聚合关系的区别:

  1. 组合关系:一只狗可以生多只小狗,但每只小狗只有一个妈妈(具有相同的生命周期)。
  2. 聚合关系:一个老师有很多学生,但每个学生又有多个老师(具有不同的生命周期)。

透明组合模式的写法:透明组合模式把所有的公共方法都定义在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 List<CourseComponent> 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 i=0;i<this.level;i++){System.out.print(" ");}for(int i=0;i<this.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 List<CourseComponent> 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 i=0;i<this.level;i++){System.out.print(" ");}for(int i=0;i<this.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/355329/

相关文章:

  • 云课堂哪个网站做的好厦门关键词优化seo
  • 中企动力沈阳分公司seo免费诊断电话
  • 网站vps被黑湖人最新排名最新排名
  • 如何夸奖客户网站做的好seo课程心得体会
  • 有哪些做电子商务的网站时空seo助手
  • 临沂百度网站电脑培训机构哪个好
  • 无锡专业做网站的公司怎样把自己的产品放到网上销售
  • 大学网站建设管理办法推广技巧
  • 长春做网站公司seo关键词排名优化软件怎么选
  • 网站开发未按合同约定工期完工seo关键词排名怎么提升
  • 创可贴app海报制作网站百度seo优化方法
  • 龙岗品牌网站建设2024年新闻摘抄
  • 南阳住房和城乡建设厅网站招聘网站排名
  • 如何做网站活动封面建站的公司
  • 温州网站建设培训营销推广方案包括哪些内容
  • 厦门 建网站商业软文案例
  • wordpress读者墙站长之家seo工具包
  • 网站建设哪家好灵活苏州久远网络北京搜索引擎关键词优化
  • 网站优化怎么做 有什么技巧东莞seo建站
  • 什么网站可以做游戏机疫情最新数据消息
  • 企业网站开发报价单巩义网络推广
  • 网站开发技术交流群免费域名申请网站
  • 手机网站一键分享怎么知道自己的域名
  • 做网站 做好把我踢开北京网站搭建哪家好
  • 网站如何做引流刷外链网站
  • wordpress 站点地址关注公众号一单一结兼职
  • 合肥网站建设第一品牌个人seo外包
  • 省心的免费建站服务热线四川seo关键词工具
  • 网站总是跳转dede58seo对网络推广的作用是
  • seo排名怎么提高seo排名优化软件有用