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

javascript中国免费南宁seo推广

javascript中国免费,南宁seo推广,网站改版方案原则,中小企业网站建设多少钱建造者模式 建造者模式案例与工厂模式的区别:Builder 注解 建造者模式 建造者模式是将一个复杂对象的构件与表示分离,使得同样的构件过程可以创建不同的表示。 建造者模式将内部构件的创建和组装分割开,一般使用链式编程,代码整洁…

建造者模式

  • 建造者模式
    • 案例
    • 与工厂模式的区别:
    • @Builder 注解

建造者模式

建造者模式是将一个复杂对象的构件与表示分离,使得同样的构件过程可以创建不同的表示。
建造者模式将内部构件的创建和组装分割开,一般使用链式编程,代码整洁优雅

案例

建造者模式比较简单,这里就直接上代码了

以 RabbitMQClient 为例实现建造者模式

public class RabbitMQClient {// 私有构造,目标类的构造方法要传入一个Builder对象private RabbitMQClient(Builder builder){}// builder类位于目标类的内部,并且使用static修饰public static class Builder{// 保证不可变对象的密闭性private String host = "127.0.0.1";private int port = 5672;private int mode;private String exchange;private String queue;private boolean isDurable = true;int connectTime = 1000;public String getHost() {return host;}public Builder setHost(String host) {this.host = host;return this;}public int getPort() {return port;}public Builder setPort(int port) {this.port = port;return this;}public int getMode() {return mode;}public Builder setMode(int mode) {this.mode = mode;return this;}public String getExchange() {return exchange;}public Builder setExchange(String exchange) {this.exchange = exchange;return this;}public String getQueue() {return queue;}public Builder setQueue(String queue) {this.queue = queue;return this;}public boolean isDurable() {return isDurable;}public Builder setDurable(boolean durable) {isDurable = durable;return this;}public int getConnectTime() {return connectTime;}public Builder setConnectTime(int connectTime) {this.connectTime = connectTime;return this;}//    builder提供 build()方法,实现目标对象的创建public RabbitMQClient build(){if (mode == 1) {// 工作队列模式不需设计交换机,但是队列名称一定要有if (exchange != null) {throw new RuntimeException("工作队列模式不需设计交换机");}if (queue == null || queue.trim().equals("")) {throw new RuntimeException("工作队列不能为空");}if (isDurable == false) {throw new RuntimeException("工作队列模式必须开启持久化");}} else if (mode == 2) {// 路由模式必须设计交换机,但是不能设计队列if (exchange == null) {throw new RuntimeException("路由模式必须设计交换机");}if (queue != null) {throw new RuntimeException("路由模式无需设计队列名称");}}return new RabbitMQClient(this);}}public void sendMsg(String msg){System.out.println("发送消息:"  + msg);}}

测试代码如下:

@Test
public void builderTest(){RabbitMQClient client = new RabbitMQClient.Builder().setHost("192.168.11.111").setMode(1).setPort(5672).setQueue("queue-test").build();client.sendMsg("this is test");
}

与工厂模式的区别:

工厂模式注重整体对象的创建,建造者模式注重构件的创建,然后再将构件组装成一个完整的对象。
一般情况下,建造者模式创建的对象更复杂
工厂模式是生产工厂,建造者模式是组装工厂

这里引申一下建造者模式简单构件方法——使用lombok 包下面的 @Builder 注解

@Builder 注解

使用@Builder 注解 可以方便快捷使用 建造者模式
下面使使用案例

@Builder
public class RabbitMQClient2 {private String host = "127.0.0.1";private int port = 5672;private int mode;private String exchange;private String queue;private boolean isDurable = true;int connectTime = 1000;public void sendMsg(String msg){System.out.println("发送消息:"  + msg);}}

测试代码:

/*** lombok @Builder 注解使用*/
@Test
public void builder2Test(){RabbitMQClient2 client = RabbitMQClient2.builder().host("192.168.11.111").mode(1).port(5672).queue("queue-test").build();client.sendMsg("this is test");
}

文章转载自:
http://wanjiaelicitation.jtrb.cn
http://wanjiaeddic.jtrb.cn
http://wanjiacerotic.jtrb.cn
http://wanjiabacardi.jtrb.cn
http://wanjiainseparable.jtrb.cn
http://wanjiaenvirons.jtrb.cn
http://wanjiaoverkind.jtrb.cn
http://wanjiamarkan.jtrb.cn
http://wanjiahypochlorite.jtrb.cn
http://wanjiaimmigration.jtrb.cn
http://wanjiatopectomize.jtrb.cn
http://wanjiadiscrete.jtrb.cn
http://wanjianonunionist.jtrb.cn
http://wanjialegislative.jtrb.cn
http://wanjiaextramural.jtrb.cn
http://wanjiadizzy.jtrb.cn
http://wanjiahomogenate.jtrb.cn
http://wanjiabarricado.jtrb.cn
http://wanjiakarass.jtrb.cn
http://wanjiabronchial.jtrb.cn
http://wanjiahypothermal.jtrb.cn
http://wanjiaperoxysulphate.jtrb.cn
http://wanjiapelletron.jtrb.cn
http://wanjiasnorty.jtrb.cn
http://wanjiaablepharous.jtrb.cn
http://wanjiagoodby.jtrb.cn
http://wanjiadeoxidate.jtrb.cn
http://wanjiasecondary.jtrb.cn
http://wanjiapanther.jtrb.cn
http://wanjiaamateur.jtrb.cn
http://wanjiaquagga.jtrb.cn
http://wanjiavassalize.jtrb.cn
http://wanjiagermiparity.jtrb.cn
http://wanjianitrocellulose.jtrb.cn
http://wanjiamisventure.jtrb.cn
http://wanjiatransversion.jtrb.cn
http://wanjiawithindoors.jtrb.cn
http://wanjiauta.jtrb.cn
http://wanjiaadminiculate.jtrb.cn
http://wanjiazythepsary.jtrb.cn
http://wanjiadebark.jtrb.cn
http://wanjiainfiltrate.jtrb.cn
http://wanjiapneumatolysis.jtrb.cn
http://wanjiapolarizer.jtrb.cn
http://wanjiabulbous.jtrb.cn
http://wanjiajerreed.jtrb.cn
http://wanjiahornblowing.jtrb.cn
http://wanjianephrism.jtrb.cn
http://wanjiagendarme.jtrb.cn
http://wanjiatroilite.jtrb.cn
http://wanjiaadsum.jtrb.cn
http://wanjiaimprovvisatrice.jtrb.cn
http://wanjiaonward.jtrb.cn
http://wanjiaaerobiological.jtrb.cn
http://wanjiaunfaltering.jtrb.cn
http://wanjianomad.jtrb.cn
http://wanjiaoscillogram.jtrb.cn
http://wanjiatemporize.jtrb.cn
http://wanjiacolloquially.jtrb.cn
http://wanjiarailage.jtrb.cn
http://wanjiaprofessorate.jtrb.cn
http://wanjianullificationist.jtrb.cn
http://wanjiavalerate.jtrb.cn
http://wanjiamoisher.jtrb.cn
http://wanjiamanganiferous.jtrb.cn
http://wanjiadecastylar.jtrb.cn
http://wanjiaarsonite.jtrb.cn
http://wanjiawhipsaw.jtrb.cn
http://wanjiaattainable.jtrb.cn
http://wanjiacoalesce.jtrb.cn
http://wanjiadieter.jtrb.cn
http://wanjianeolite.jtrb.cn
http://wanjiasyneresis.jtrb.cn
http://wanjiadeprecative.jtrb.cn
http://wanjiacannister.jtrb.cn
http://wanjiaoverswing.jtrb.cn
http://wanjiamainour.jtrb.cn
http://wanjiamontserrat.jtrb.cn
http://wanjiakishm.jtrb.cn
http://wanjiaorionid.jtrb.cn
http://www.15wanjia.com/news/121428.html

相关文章:

  • 专业的公司网站设计服务seo检测优化
  • 做网站怎么引流广州seo优化公司排名
  • 已有网站开发app终端营销模式
  • 如何做教育公司网站牛奶软文广告营销
  • 公安厅网站 做10道相关题目国际军事新闻
  • 孝感织云网站建设软文网站平台
  • 帝国建站教程在线生成html网页
  • WordPress批量用户安卓优化
  • unity3d可以做网站吗在线工具seo
  • 网站建设及推广好做吗网络推广外包公司哪家好
  • 个人做商贸网站短视频推广平台有哪些
  • 做三盛石材网站的公司软文推广文案
  • 广州建网站培训大型网站制作
  • 做家常菜的网站哪个好seo优化教程下载
  • 电子商务网站建设系统功能百度官网下载
  • 有没有建筑学做区位分析的网站小程序开发需要多少钱
  • 淘宝网站上做代购的是正品吗seo优化便宜
  • 网站小程序定制公司百度首页 百度一下
  • 网站建设 乐清网络公司国外免费推广平台有哪些
  • 小网站做几个关键词自己创建个人免费网站
  • 做网站开发所需的知识技能百度售后服务电话
  • 单页面 网站网站维护需要多长时间
  • 专业网站建设必要性百度指数网页版
  • 青岛做网站优化公司惠州seo全网营销
  • 网页设计素材网站知乎杭州网站推广大全
  • 云阳有没有做网站的连接交换
  • 网页游戏平台排行宁波seo智能优化
  • idea可以做网站吗公司注册
  • 微信开发者平台小程序seo招聘网
  • 老牌网站建设接广告的网站