- 1、本文档共16页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
5.2.某电影院售票系统为不同类型的用户提供了不同的电影票(CinemaTicket)打折方式
(Discount),学生凭学生证可享受8 折优惠(StudentDiscount),儿童可享受减免10 元的优惠
(ChildrenDiscount) , VIP 用户除享受半价优惠外还可以进行积分(VIPDiscount)。选择一种合
适的设计模式来设计该系统。(策略模式)
MovieTicket
- price : double Discount
- discount : Discount
+ setPrice (double price) : void + calculate (double price) : double
+ setDiscount (Discount discount) : void
...
+ getPrice () : double
...
StudentDiscount VIPDiscount
+ calculate (double price) : double + calculate (double price) : double
... ...
ChildrenDiscount
+ calculate (double price) : double
...
// 电影票类:环境类
class MovieTicket
{
private double price;
private Discount discount;
public void setPrice(double price)
{
this.price = price;
}
public void setDiscount(Discount discount)
{
this.discount = discount;
}
public double getPrice()
{
return discount.calculate(this.price);
}
}
//折扣类:抽象策略类
interface Discount
{
public double calculate(double price);
}
//学生折扣类:具体策略类
class StudentDiscount implements Discount
{
1
public double calculate(double price)
{
return price * 0.8;
}
}
//儿童折扣类:具体策略类
class ChildrenDiscount implements Di
您可能关注的文档
最近下载
- (完整版)电气设备安装标准规范.pdf
- GB∕T 13861-2022生产过程危险和有害因素分类、解读与示例说明清单【危险源识别工具】(雷泽佳-2024A0).doc
- 2021年中国光大银行校园招聘在线测试笔试题考试真题笔经.doc
- 新浪·按键精灵开发者1级认证参考解析.docx VIP
- 2023年福建省各地中考语文模拟卷【文学类文本阅读题解及答案解析】汇集.docx VIP
- 皮亚杰认知发展论.ppt VIP
- 2.1 几代中国人的美好夙愿 课件初中读本.ppt
- 流域化“厂网一体”运营模式的探索与实践.pdf
- 半导体制造技术离子注入工艺.pptx
- 全国普通话水平测试用普通话词语表(表一+表二).pdf
文档评论(0)