I'm in the middle of creating domain model and I need help with some entities. I have a Sale
entity (which represents the action of selling goods to buyers) and a Purchase
entity (which represents the act of buying goods from supplier to fill the stocks). I see the two ways of how to deal with it:
Sell
and Purchase
and additional entities for both of them named like Sell details
and Purchase details
respectively, with attributes [sell_id
/purchase_id
, product_id
, ..., quantity
]. But in this case I will have two almost identical entities in my database which is obvious duplication of data.Order
with additional attribute order_type
(and eponymous entity to store order types: purchase
and sell
) and Order_details
entity so we can escape data duplication from the first approach.Please share your experience how to deal with this case. Thanks.
A business organization has both sales orders and purchase orders. Both object types may share quite some part of their structure, but they may also have attributes/operations/constraints that are not shared. In particular, for a business, sales orders (and the sales department) are typically more important than purchase orders (and the purchasing department). For their sales orders, they have operations like availability check, delivery scheduling and credit limit check, which they don't have for purchase orders.
It's normally not worthwhile to try finding an (abstract) super type of all the different types of orders of an organization (such as sales/purchase/transport/production/etc. orders) and use subtyping/inheritance for sharing some of their structural definitions.