人工智能在建筑运营

构建API时,您应始终考虑谁将使用它。 当API简单易用时,用户就会感到满意。 当用户满意时,每个人也都会满意。 但是出色的可用性并非总是容易实现的。 有一些模式对此有所帮助,在这篇文章中,我将重点介绍经典的构建器模式,以及如何使用步进构建器模式对其进行增强,以构建没有大脑接口,易于使用且不会出错的对象 。 因此,让我们开始绘制一些上下文,我们有2个域对象代表连接到某个远程或本地服务器的用户配置。 当需要远程凭据时,在本地时。

package com.marco.sbp;
public class UserConfiguration {private final String name;private ServerDetails serverDetails;public UserConfiguration(String name) {this.name = name;}public void setServerDetails(ServerDetails serverDetails) {this.serverDetails = serverDetails;}public String getName() {return name;}public ServerDetails getServerDetails() {return serverDetails;}
}
package com.marco.sbp;
public class ServerDetails {private final String host;private String user;private String password;public ServerDetails(String host) {this.host = host;}public void setUser(String user) {this.user = user;}public void setPassword(String password) {this.password = password;}public String getHost() {return host;}public String getUser() {return user;}public String getPassword() {return password;}
}

我们想要使用两种不同的技术(经典构建器模式和步骤构建器模式)来抽象上述对象的构造。

经典的构建器模式非常简单,它使用诸如onLocalHost,onRemoteHost等正确命名的方法来掩盖UserConfiguration和ServerDetails的创建。

package com.marco.sbp.builder;
import com.marco.sbp.ServerDetails;
import com.marco.sbp.UserConfiguration;
public class ClassicBuilder {private String name;private String host;private String user;private String password;public ClassicBuilder(String name){this.name = name;}public ClassicBuilder onLocalHost(){this.host = "localhost";return this;}public ClassicBuilder onRemoteHost(String remoteHost){this.host = remoteHost;return this;}public ClassicBuilder credentials(String user, String password){this.user = user;this.password = password;return this;}public UserConfiguration build(){UserConfiguration userConfiguration = new UserConfiguration(name);ServerDetails serverDetails = new ServerDetails(host);serverDetails.setUser(user);serverDetails.setPassword(password);                    userConfiguration.setServerDetails(serverDetails);return userConfiguration;}
}

步骤构建器模式仍在使用智能名称来构造对象,但仅在需要使用接口和适当的封装时才公开这些方法。

package com.marco.sbp.builder;
import com.marco.sbp.ServerDetails;
import com.marco.sbp.UserConfiguration;/** "Step Builder" */
public class StepBuilder {public static NameStep newBuilder() {return new Steps();}private StepBuilder() {}public static interface NameStep {/*** @param name*            unique identifier for this User Configuration* @return ServerStep*/ServerStep name(String name);}       public static interface ServerStep {/*** The hostname of the server where the User Configuration file is stored will be set to "localhost".* * @return BuildStep*/public BuildStep onLocalhost();/*** The hostname of the server where the User Configuration file is stored.* * @return CredentialsStep*/public CredentialsStep onRemotehost(String host);}public static interface CredentialsStep {/*** Username required to connect to remote machine Password required to connect to remote machine* * @return BuildStep*/public BuildStep credentials(String user, String password);}public static interface BuildStep {/*** @return an instance of a UserConfiguration based on the parameters passed during the creation.*/public UserConfiguration build();}private static class Steps implements NameStep, ServerStep, CredentialsStep, BuildStep {private String name;private String host;private String user;private String password;public BuildStep onLocalhost() {this.host = "localhost";return this;}public ServerStep name(String name) {this.name = name;return null;}public CredentialsStep onRemotehost(String host) {this.host = host;return this;}public BuildStep credentials(String user, String password) {this.user = user;this.password = password;return this;}public UserConfiguration build() {UserConfiguration userConfiguration = new UserConfiguration(name);ServerDetails serverDetails = new ServerDetails(host);serverDetails.setUser(user);serverDetails.setPassword(password);                    userConfiguration.setServerDetails(serverDetails);return userConfiguration;}}
}

现在让我们看一下两个构建器的用户体验。 经典构建器将使用用户配置的名称进行构造,然后它将公开其所有方法,从而使用户过于自由,无法选择下一步。

例如,一个不小心的用户可能最终将UserConfiguration设置为localhost,而无需身份验证,仍然传递用户名和密码。

这令人困惑,并且可能导致运行时异常。

这些是用户可能最终得到的UserConfigurations的一些可能组合,其中一些是正确的,很多是错误的:

步骤构建器有一个完全不同的故事,这里仅显示了当时的一个步骤:

如果不需要凭据,则不会公开它们,只有在确定对象状态一致且完整时才提供build()方法:

使用此模式只能构建2个可能的UserConfigurations,它们既有意义又对用户清晰。

结论

步骤构建器模式不是经典Bloch 模式的替代,有时您想强迫用户在进行创建之前填充一些参数,在这种情况下,步骤构建器正在执行此工作,否则当需要更开放的方法时比经典的建造者更适合您

参考:从我们的JCG合作伙伴 Marco Castigliego 构建智能建筑商 ,位于“ 删除重复和修复不良名称”博客中。

翻译自: https://www.javacodegeeks.com/2013/05/building-smart-builders.html

人工智能在建筑运营

人工智能在建筑运营_打造智能建筑商相关推荐

  1. 人工智能快速发展 计算机视觉产品打造智能社会“入口”

    3月28日,2017人工智能·计算机视觉产业创新大会在北京举行.来自政府.高校.研究机构的领导.专家和学者,与现场近500位行业人士齐聚一堂,共同探讨人工智能计算机视觉的技术发展路径和产业演进过程,以 ...

  2. mxm智能教育机器人无法智能对话_零代码使用腾讯TBP打造智能对话机器人

    点击观看大咖分享 心疼你独自一人承担生活的苦难,寂寞夜里陪伴你的只剩无人倾诉的压抑和无处安放的焦虑.养个宠物,它却不能get到你的"宠言宠语".找个伴侣,还要浪费吵架的时间和精力. ...

  3. 长隆大马戏机器人_腾讯长隆打造智能主题酒店 小Q机器人全面部署智慧旅游

    原标题:腾讯长隆打造智能主题酒店 小Q机器人全面部署智慧旅游 作为国内互联网行业最具知名度的品牌形象,腾讯QQ那只胖胖的企鹅可以说是陪伴几代人的互联网启蒙.就在前不久,腾讯与长隆集团达成战略合作,联合 ...

  4. 机器人新车号牌安装_手把手教你打造智能小车(0)-写在前面的话

    每个男孩都有一个机器人的梦,这个梦也许就是从第一次玩遥控汽车玩具开始的.只是那时的男孩还不能够明白,神奇的小车为什么能够按照自己的指令行动,随着知识的增长,他开始明白了一个叫做电磁波的东西传递这其中的 ...

  5. 心脏病_冠心病智能预测模型(人工智能,机器学习,用于论文作业_专利_企业建模__项目申报_科研报告,收藏)

    作者Toby,来自心脏病_冠心病智能预测模型 ​ 心脏病(heart disease)是心脏疾病的总称,包括风湿性心脏病.先天性心脏病.高血压性心脏病.冠心病.心肌炎等各种心脏病. 人体"发 ...

  6. 为什么集合可以自动扩充_人工智能配色系列(二)智能扩充

    随着人工智能的高速发展,通过算法学习设计师的设计方法,并由机器自动生成Banner,尤其是电商类Banner,以减少设计师的低创意.重复性的工作,已然成为人工智能时代的大势所趋.而智能配色又是生成Ba ...

  7. 助理来也胡一川:用数据驱动打造智能行业助理(技术+业务)

    作者简介: 胡一川,来也联合创始人 & CTO,前"今晚看啥"联合创始人,于清华大学硕士毕业,之后前往宾夕法尼亚大学并拿到电子与系统工程系博士学位.回国开始创业,作为联合创 ...

  8. 华为轮值CEO郭平:与伙伴同行,打造智能社会五朵云之一

    9月5日,华为全联接大会在上海开幕.华为轮值CEO郭平发表主题演讲<与伙伴同行,打造智能社会五朵云之一>. 以下为郭平演讲全文: 各位嘉宾,各位朋友,早上好: 欢迎大家出席华为全联接大会. ...

  9. 【观察】从鞍钢数字化转型升级,看如何打造智能制造数据坚实底座?

    申耀的科技观察 读懂科技,赢取未来! 过去几年,随着国内钢铁行业去产能任务逐步完成,钢铁行业逐步由规模性调整进入质量效益性调整的新阶段,同时行业由增量竞争逐渐进入存量竞争,低成本.高效率和优质服务以及 ...

最新文章

  1. java中native的用法[转]
  2. python千位分隔符_python – 为pandas数据帧中的整数设置千位分隔符
  3. SringBoot/Cloud/Aalibab 事务管理
  4. Filezilla 服务器发回了不可路由的地址。使用服务器地址代替
  5. 对比A,B两张表,将相同的记录写到M表,不同的记录全部写到N表中
  6. 湖南师范大学2018年大学生程序设计竞赛新生赛 A 齐神和心美的游戏【hash】
  7. 那些年你不能错过的之【Linux操作】
  8. 网络调试助手连接远程服务器
  9. java单链表反转(头插法)详解
  10. 官宣!湖北高校尽量不延迟毕业时间
  11. 最in [IN词] 分享
  12. 通过apk签名使应用程序有系统权限
  13. mongodb $符号的神奇用法+mongo数据类型
  14. Linux C语言IO多路转接select函数
  15. lego-loam数据_使用lego minifigures数据集在fastai中对datablocks api图像进行分类
  16. ajax访问如何重定向,ajax请求重定向
  17. mac数据库操作(忘记密码)
  18. JSON Schema定义 +Networknt validator格式校验
  19. 怎么在Win7服务器搭建SVN服务端
  20. Dockerfile 搭建Redis 高可用

热门文章

  1. Hadoop入门(十四)Mapreduce的数据去重程序
  2. Spring @Qualifier 注释
  3. 装饰器模式(讲解+应用)
  4. Spring入门(一)之简介
  5. hibernate正向生成数据库表以及配置——hibernate.cfg.xml
  6. SpringBootAdmin安全配置
  7. ❤️ 爆肝一个月!JAVA零基础入门总结(下)❤️
  8. mybatis generator Unknown system variable 'query_cache_size' 的解决方法
  9. Multi-catch parameters are not allowed for source level below 1.7 解决方法
  10. Comparable and Comparator API