I need to represent the payment of a customer to buy a flight ticket in an airport. The system of airport has a bonus system.
So customer can make payment for ticke
You should start with a model of the problem domain. I would expect something like the following:
This diagram states that:
Customer
offers one or more Payment
s to a Payment Service
Payment Service
accepts one or more Payments
offered by a Customer
Payment
has an amount
Payment
must be a Mileage Payment
, Cash Payment
, or Credit Card Payment
Payment
sTo then answer your question in terms of the solution domain, I would have your pay()
method accept a collection of payments. You don't need subordinate interfaces for each kind of Payment
, only various class implementations. I would use polymorphic operations to debit (if that's the right word), roll back if anything fails, and commit when all the debits succeed.