运维之自动化SHELL脚本
2013-11-15 18:21
477 查看
public class Bread { //所有原料单位为g //必须原料 private double water; private double flour; private double soda; //以下都是可选原料 private double salt; private double suger; private double fat; private double egg; private Bread(Build build) { this.egg = build.egg; this.fat = build.fat; this.flour = build.flour; this.salt = build.salt; this.soda = build.soda; this.suger = build.suger; this.water = build.water; } public static class Build { //必须原料 private double water; private double flour; private double soda; //以下都是可选原料 private double salt; private double suger; private double fat; private double egg; public Build(double water, double flour, double soda) { this.water = water; this.flour = flour; this.soda = soda; } public Build salt(double val) { this.salt = val; return this; } public Build suger(double val) { this.suger = val; return this; } public Build fat(double val) { this.fat = val; return this; } public Build egg(double val) { this.egg = val; return this; } public Bread build() { return new Bread(this); } } @Override public String toString() { return String.format("蛋:%.2f 油:%.2f 面粉:%.2f 盐:%.2f 苏打:%.2f 糖:%.2f 水:%.2f", this.egg, this.fat, this.flour, this.salt, this.soda, this.suger, this.water); } public static void main(String[] args) { System.out.println(new Build(500.0, 200.0, 30.5).egg(10.2).fat(15.5).build()); } }
内部类+建造者模式,当一个物体有很多可选参数的时候,是一个绝佳的设计模式。
hibernate的sessionfactory和jpa的entitymanger应该用了同样的实现。
相关文章推荐
- 自动化运维-使用Shell脚本简单实现
- Linux自动化运维之Shell脚本(初出茅庐)
- CentOS 下运维自动化 Shell 脚本之 expect
- 手游公司运维之利用Rundeck自动化运维工具和Shell脚本构建测试环境代码发布平台和生产环境代码发布平台
- 运维与自动化系列③自动化部署基础与shell脚本实现
- 运维与自动化系列③自动化部署基础与shell脚本实现
- Shell脚本-自动化部署WEB
- shell脚本自动化部署XX的案例(附数组使用)
- 自动化部署java maven项目到多个目标主机的Shell脚本
- 实用自动化运维Python脚本
- 作业:Rsync+shell脚本完成自动化备份
- Shell脚本实现自动化安装
- SHELL脚本之自动化安装通用二进制格式MariaDB
- shell脚本自动化--bond
- Hive结合shell脚本实现自动化业务
- Hive结合shell脚本实现自动化业务
- [置顶] 编写shell脚本实现自动化搭建安装LNMP平台全过程配置详解
- 简易登录,批量执行命令,批量copy文件shell脚本【Linux运维之道之脚本案例】
- 用shell脚本自动化备份数据库
- 使用shell脚本自动化对硬盘进行分区