educative.io

Coupon and payment unidirectional relationship?


#1

Coupon and payment have a unidirectional relationship. How can we write that in code? It seems absurd to me that coupon knows about payment. It should be the other way. Is it?


#2

@Pooja_Sheoran, It depends how the requirements are laid out. Based on the current design a payment can’t have more than one coupon, whereas a coupon can be applied to multiple payments. If we can ask the coupon to find all the payments where it has been applied then the coupon class will know about payment. On a similar lines, as you have pointed out too, the payment can know about the coupon it has. So if we take both of these requirements then the relationship will be bi-directional association.


#3

Thanks for the reply