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

想开个影视网站 那有做的莱芜信息平台

想开个影视网站 那有做的,莱芜信息平台,华容网站建设,崂山区建设管理局网站怎么了黑构建API时#xff0c;您应该始终考虑谁将使用它。 当API简单易用时#xff0c;用户就会感到满意。 当用户满意时#xff0c;每个人也都会满意。 但是出色的可用性并非总是容易实现的。 有一些模式对此有所帮助#xff0c;在这篇文章中#xff0c;我将重点介绍经典的构建器… 构建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;} } 我们希望使用两种不同的技术经典的构建器模式和步骤构建器模式来抽象上述对象的构造。 经典的构建器模式非常简单它使用诸如onLocalHostonRemoteHost等正确命名的方法来掩盖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
http://www.zqtcl.cn/news/399318/

相关文章:

  • 常州市金坛区网站建设毕业设计代做淘宝好还是网站好
  • 品牌网站建设营销型网站设计网站整合方案
  • 网站开发设计师网站代理什么意思
  • 网站层级关系邯郸品牌商标vi设计策划公司
  • 网站开发产品需求说明小网站代码
  • 苏州网站推广排名网站建设方案范文8篇
  • 自己做考试题目网站广州番禺区美食攻略
  • 广州做网站如何如何制作一个网页
  • 网站定制开发收费标准是多少网站代码优化方案
  • 制作卡牌的网站深圳正规煤气公司
  • 手表网站哪家好网站用图片
  • 群辉nas 做网站wordpress linux 中文
  • 平面设计素材网站排名巩义网站建设方案表
  • 延庆网站制作搜索引擎优化的基础是什么
  • 管理手机网站商城网站备案流程
  • 怀化买房网站网站广告js代码添加
  • 做网站 帮别人卖服务器wordpress主题多页面
  • 代理游戏网站潍坊市建设工程管理处网站
  • 大同推广型网站建设网站规划建设与管理维护第二版答案
  • 做网站需要代码吗户外媒体网站建设免费
  • 做什么网站国外做图标网站
  • 网站建设技术部职责门户网站工作总结
  • 用个人电脑做服务器建网站急切网头像在线制作图片
  • 企业网站制作教程浙江省住房和城乡建设厅网站
  • 一个网络空间如何做两个网站哪个网站兼职做设计比较好
  • jquery代码做的网站免费搭建网站模板
  • 铁路建设监理协会官方网站邯郸市网
  • 马鞍山集团网站建设客流分析系统公司
  • 淘客网站怎么做啊抖音怎么挂小程序赚钱
  • 在哪里申请网站域名美妆销售网站开发的目的