use a premium booking process depends upon the status of the customer. Let's assume an elite customer gets premium booking while a regular customer gets the regular treatment. In this case, of course, we shouldn't have a boolean flag - but is the customer object itself acting as a flag?
I would look at this as about capturing the intention of the caller. If how to book depends only on the status of the customer, then the caller has no business caring about the difference between premium and regular booking - and thus it's perfectly reasonable for the booking routine to derive it's true method based on the customer status. You only want different methods when the caller needs to specify which one she wants.
class Customer { constructor(private bookingStrategy) {} setBookingStrategy(strategy) { // } } I think this is the better way instead of inheritance, EliteCustomer extends Customer
Elite customer is just an example to point out the case that the caller has no business caring
Обсуждают сегодня