0

I want to design a domain model for the following system:

  • a customer asks a hotel for rooms availability and prices on a date
  • the hotel send several offers: room type x, price Y, etc
  • the customer accepts an offer and makes a reservation.

One way of looking at it is that a reservation it's just an offer "flagged" as accepted.

So my question is: should I introduce only one entity called "Offer" or Reservation and Offer should be 2 separate entities?

Will it depend on the complexity of the system (meaning that with so little information it's hard to say) or it's already clear what to do?

What could be the potential drawbacks of introducing only one entity?

1
  • Offer and Reservation should be completely seperate entities because they represent two different concepts. In terms of complexity of the system, representing them as different things is preferrable since it seperates the concerns. For example, if you need to change/fix the offer class it wont be mixed in with the reservation class. The drawbacks of introducing only 1 entity are that it will end up larger (since you have 2 classes in 1) and also make less sense since the code for an offer will be tangled with the code for a reservation.
    – user362602
    Commented Mar 30, 2021 at 8:52

1 Answer 1

2

The chief drawback is mutability and the confusion that causes. Say a Reservation must be secured with a credit card. A Reservation that is really just an offer now would have to leave the credit card blank and fill it in later. Which means you can’t tell if a Reservation is valid without checking.

If you separate them then old fashioned constructor validation ensures that a Reservation is real. You can build them by sucking details out of an Offer or just link to one.

When you separate them, a Reservation and an Offer can both be trusted to fully work just because they exist.

1
  • 2
    Agree, it's so much cleaner separating offer from reservation. Also, from a domain perspective they are two (very) different things. Commented Mar 28, 2021 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.