Imagine we have two types of requests, an InvoiceRequest and a QuoteRequest. How would you prefer the object model (classes) be and the database model ? Which one of the following two make more sense ?
InvoiceRequest:
- id
- amount
- discount
- date
- invoiceSpecificFieldHere
QuoteRequest:
- id
- amount
- discount
- date
- quoteSpecificFieldHere.
Or does this one make more sense?
RequestData:
- amount
- discount
- date
InvoiceRequest:
- id
- requestData: <RequestData>
- invoiceSpecificProperty
QuoteRequest:
- id
- requestData: <RequestData>
- quoteSpecificProperty.
I'm not representing a third option using inheritance in purpose.
The question behind this question, is the following; if we go with design 2, we reduce redundancy, however there is something about it that doesn't make me feel comfortable. Which is the fact that reality is not captured correctly. I would argue that discount should be at the same level as quoteSpecificProperty. And putting it inside a box (the requestData object) is a departure from what this represents in the world.
Aucun commentaire:
Enregistrer un commentaire