您现在的位置: 天极网 > 开发频道 > 动态扩展Java应用
全文

动态扩展Java应用

2001-11-26 16:24作者:QQ新人类出处:yesky责任编辑:方舟

  不使用interface的编码

  开始编码时你可以不使用接口,然后再由该代码增强其功能。现在,该客户有两个标价计划定义如下:

  计划1:对于常规的顾客,$20/交易

  计划2:一个月中的前10个交易,$15/交易,以后的 $10/交易

  Trade对象使用一个PricingPlan对象来计算要收顾客多少佣金。你为每个标价计划都创建了一个PricingPlan类。对于计划1,该类称为PricingPlan20,而计划2的类则称为PricingPlan1510。两个类都通过一个称为CalcCommission()的过程来计算佣金。代码如下所示:

  类名: PricingPlan20

public double calculateCommission( Trade trade )
{
 return 20.0;
}


类名: PricingPlan1510

public double calculateCommission( Trade trade )
{
 double commission = 0.0;

 if( trade.getCustomer().getNumberOfTradesThisMonth() <= 10 )
   commission = 15.0;
 else
   commission = 10.0;

 return commission;
}

  以下是在交易中得到佣金的代码:

public double getCommissionPrice()
{
 double commissionPrice = 0.0;

 if( getCustomer().getPlanId() == 1 )
 {
  PricingPlan20 plan1 = new PricingPlan20();
  commissionPrice = plan1.calculateCommission( this.getCustomer() );
  plan1 = null;
 }
 else
 {
  PricingPlan1510 plan2 = new PricingPlan1510();
  commissionPrice = plan2.calculateCommission( this.getCustomer() );
  plan2 = null;
 }

 return commissionPrice;
}
共6页。 9 1 2 3 4 5 6 :

软件资讯·软件下载尽在天极软件

相关搜索:
相关文章及软件
关注此文读者还看过
热门关注
特别推荐
网友关注
软件下载
娱乐下载
驱动下载
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众