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

做直播网站软件有哪些线上推广费用预算

做直播网站软件有哪些,线上推广费用预算,邢台网站建设平台,天河网站建设服务享元模式 享元模式(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.tj-hxxt.cn/news/83189.html

相关文章:

  • 网站建设 要学多久上海有实力的seo推广咨询
  • 同一个域名可以做几个网站吗seo网址超级外链工具
  • 网站推广免费渠道seo服务外包客服
  • 南宁网站设计平台手机如何建网站
  • 网站编程培训公司搜索引擎优化概述
  • 古典asp网站源码江北关键词优化排名seo
  • 学校网站搭建运营推广是做什么的
  • ASP.NET动态网站开发百度提交入口的网址
  • 彩票娱乐网站建设开发宁波seo外包平台
  • 做网站猫腻大吗seo云优化外包
  • 自己做网站卖矿山设备百度推广代理开户
  • 监理网站长沙做优化的公司
  • 怎么给自己的网站做域名上海百度关键词推广
  • 简单做网站的价格网络seo是什么意思
  • 个人工作室的网站网络营销外包公司
  • 广州疫情风险等级seo商城
  • 做磁力链网站西安网红
  • 广西做网站公司有哪些流量精灵app
  • 网页代码制作基础教程搜索引擎优化指的是
  • 网站被攻击如何处理韩国seocaso
  • 选择邯郸做网站百度在线扫一扫
  • 做高端网站的网络公司企业网站seo多少钱
  • 要解析做邮箱以及网站搜索引擎营销的名词解释
  • 贸易公司做网站怎么样自己的app如何接广告
  • 做网站 信科网站建设便宜天津百度优化
  • 长春网站优化实战新闻头条今天最新消息
  • iis部署网站浏览报404百度关键词排名原理
  • 网站建设需要怎么做企业qq一年多少费用
  • 寄生虫网站排名代做在百度上怎么注册网站
  • 网站标题设计ps搜索引擎分哪三类