Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best design pattern for a conditional booking system

I'm building a flight booking system from a specification for my OOP class in college. The system has to be written in C#. I'm wondering what the best way to tackle the following problem would be

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.

Should I have a passenger class, from which each separate type of customer inherits from? Any help on this would be appreciated

like image 938
Darren Findlay Avatar asked Mar 13 '13 09:03

Darren Findlay


1 Answers

In my opinion you do not want to inherit from Passenger. Inheritance implies that the object changes in some way, but a passenger is a passenger no matter what discount he obtains. Put another way, his functionality does not change just because he gets a bigger discount.

This example you are using is very close to the examples usually given for the Decorator pattern, although that is usually because it demonstrates that multiple discounts can be applied to the object being decorated (Passenger in your case). Take a look at the Coffee example on wiki here

Another possibility is Strategy pattern, this gives you a clean interface for creating a Ticket for a passenger, while internally it switches the DiscountStrategy depending upon what type of passenger is requesting a ticket.

like image 155
Jamiec Avatar answered Oct 20 '22 01:10

Jamiec