加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 有条件预订系统的最佳设计模式

发布时间:2020-12-15 08:41:55 所属栏目:百科 来源:网络整理
导读:我正在建立一个航班预订系统,从我在大学的OOP课程的规范.系统必须用C#编写.我想知道解决以下问题的最佳方法是什么 The company currently operates a discount scheme. Western Isles residents get a 10% discount. Scotia also records the island of resi
我正在建立一个航班预订系统,从我在大学的OOP课程的规范.系统必须用C#编写.我想知道解决以下问题的最佳方法是什么

The company currently operates a discount scheme. Western Isles residents get a 10% discount.
Scotia also records the island of residence of these passengers for marketing purposes. Business
travellers get a 25% discount and must supply their company name. Ordinary passengers do not
normally receive a discount unless it is part of a current promotion,in which case they receive a
5% discount.

我是否应该有乘客舱,每个独立类型的客户都是从哪一类继承的?任何有关这方面的帮助将不胜感激

解决方法

在我看来,你不想继承Passenger.继承意味着对象在某种程度上发生了变化,但无论乘客获得什么折扣,乘客都是乘客.换句话说,他的功能并没有因为他获得更大的折扣而改变.

您正在使用的这个示例非常接近通常为Decorator模式提供的示例,尽管这通常是因为它表明可以对正在装饰的对象(在您的情况下为Passenger)应用多个折扣.看看wiki here上的Coffee示例

另一种可能性是策略模式,这为您提供了一个干净的界面,用于为乘客创建票证,而在内部则根据请求票证的乘客类型切换DiscountStrategy.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读