You want the discount policy to be flexible, the passengers are actually not so different.
You may have a Customer base class from which Passenger and Company are derived, but this does not affect how you apply the discount logic.
Inheritance implies different behavior, but the behavior of passengers does not change, only the applied discounts and discount should not be part of the passengerβs state, therefore he does not fit into this class. In addition, many discounts have been active only for some time, and it makes no sense to code this in the Customer class, you should be able to add and remove them dynamically.
Since discount logic is actually a business rule that the client applies, it must be encapsulated in a separate set of classes. The general template used to implement it is strategy . Depending on your design, since you want to apply different policies for different types of users, you may find the visitor template useful or not.
source share