适配器设计模式---对象适配
来源:互联网 发布:安广网络电视怎么缴费 编辑:程序博客网 时间:2024/06/07 01:36
package cn.icer.simulation.ObjectAdapter;/** * 火箭 * @author icer * @date 2013-12-27 * */public abstract class SkyRocket {private double burnTime;private double mass;private double thrust;public SkyRocket(double mass, double thrust, double burnTime){this.mass = mass;this.thrust = thrust;this.burnTime = burnTime;}public abstract double getMass();public abstract double getThrust();public abstract void setSimTime(double time);}
package cn.icer.simulation.ObjectAdapter;/** * 火箭 * @author icer * @date 2013-12-27 * */public class PhysicalRocket {private double burnArea;//燃烧面积private double burnRate;//燃烧率private double initFuelMass;//燃料private double totalMass;//燃料总量private double totalBurnTime;//总燃烧时间//重力加速度private static double SPECIFIC_IMPULSE = 620;// Newtons/Kg//燃料密度private static double FUEL_DENSITY = 1800;// Kg / M**3public PhysicalRocket(double burnArea, double burnRate, double fuelMass, double totalMass) {this.burnArea = burnArea;this.burnRate = burnRate;this.initFuelMass = fuelMass;this.totalMass = totalMass;double initialFuelVolume = fuelMass / FUEL_DENSITY;this.totalBurnTime = initialFuelVolume / (burnArea * burnRate);}/** * * @return 燃烧时间 */public double getBurnTime(){return totalBurnTime;}/** * * @param time 燃烧时间 * @return 现在剩余的燃料 */public double getMass(double time){if ( time > totalBurnTime)return totalMass - initFuelMass;double burntFuelVolume = burnArea * burnRate * time;return totalMass - burntFuelVolume * FUEL_DENSITY;}/** * * @param time 燃烧时间 * @return 点火以来产生的总推力 */public double getThrust(double time){if (time > totalBurnTime)return 0;return FUEL_DENSITY * SPECIFIC_IMPULSE * burnArea * burnRate;}}
package cn.icer.simulation.ObjectAdapter;/** * 火箭 * @author icer * @date 2013-12-27 * */public class IcerRocket extends SkyRocket {private double time;private PhysicalRocket rocket;public IcerRocket(PhysicalRocket rocket) {super(rocket.getMass(0), rocket.getThrust(0), rocket.getBurnTime());this.rocket = rocket;}@Overridepublic double getMass() {return rocket.getMass(time);}@Overridepublic double getThrust() {return rocket.getThrust(time);}@Overridepublic void setSimTime(double time) {this.time = time;}}
0 0
- 适配器设计模式---对象适配
- c++设计模式--对象适配器模式
- C++设计模式----对象适配器模式
- 【面向对象设计模式】 适配器模式 (二)
- 适配器模式----类适配和对象适配
- 适配器模式 - 多对象适配
- 适配器模式之对象适配
- 适配器设计模式---接口适配
- [设计模式](五):适配器模式(Adapter)[类适配器、对象适配器、接口适配器]
- 适配器模式(对象适配器)
- 适配器模式-对象适配器
- 【初学设计模式】Object Adapter (对象适配器)
- 设计模式11:对象适配器【结构型】
- 设计模式-23-2-对象适配器
- JAVA设计模式-适配器(类适配器、对象适配器)模式-Adapter
- C++设计模式——适配器模式(对象适配器、类适配器)
- 【GOF23设计模式】_适配器模式、对象适配器、类适配器、开发中场景JAVA235
- 设计模式学习--适配器模式(类适配器和对象适配器)
- Android中Sdcard的操作
- ORACLE常用命令
- eclipse配置tomcat
- 展讯平台-LCD驱动
- QML中的Model View——一个ListView实例
- 适配器设计模式---对象适配
- 关于Oracle
- SQL Server架构----查询的生命周期(下)
- windows常用命令
- python中的除法和取模
- QML中的Model View——一个PathView实例
- asp.net后台如何输出js脚本
- 几个最短路径算法Floyd、Dijkstra、Bellman-Ford、SPFA的比较
- 一个互联网用户的对生活的感悟