Hi All,
I was wondering if I could get some comments on my approach to the
design of the domain model and database for my rails app. I don’t
have much experience in this so I am wondering if I am heading in the
right direction.
My app is an ecommerce site for my business which is a record label.
That might seem straight forward, but the one thing that might be
tricky is that we’ll be selling both hard and soft goods (e.g. CDs
and MP3s). I want both types of goods to be able to be added to the
same cart.
So here is my approach so far. I’ve created a class called Product
which can contain a reference to one of either SoftProduct or
HardProduct. These in turn refer/relate to a couple additional
dependent classes, depending on whether we are dealing with a hard of
soft good. So whether the Product contains a SoftProduct or a
HardProduct, the cart mechanism remains relatively simple because it
is just a matter adding a Product. All the logic of determining one
kind of attributes a Product has, which is based on what kind of
objects it contains, remains in the Product class.
Here’s a simple diagram:
| Product |
| |
| ___________________ ___________________ |
| | SoftProduct | | HardProduct | |
| | | | | |
| | ______________ | | _______________ | |
| | | Album | | | | Option | | |
| | || | | |______________| | |
| | | | | |
| | or | | | |
| | ______________ | | | |
| | | Song | | | | |
| | || | | | |
| | | | | |
| || || |
|___________________________________________|
Is this the right way to go? Or does adding this child classes
involve too much unnecessary overhead overhead in terms of extra sql
queries, etc?
Thanks,
Sean