If I use Class Table Inheritance
meaning:
one table for Products, storing attributes common to all product types. Then one table per product type, storing attributes specific to that product type.
-Bill Karwin
Which I like the best of Bill Karwin's Suggestions.. I can kind of foresee one drawback, which I will try to explain how to keep from becoming a problem.
What contingency plan should I have in place when an attribute that is only common to 1 type, then becomes common to 2, then 3, etc?
For example: (this is just an example, not my real issue)
If we sell furniture, we might sell chairs, lamps, sofas, TVs, etc. The TV type might be the only type we carry that has a power consumption. So I would put the power_consumption
attribute on the tv_type_table
. But then we start to carry Home theater systems which also have a power_consumption
property. OK its just one other product so I'll add this field to the stereo_type_table
as well since that is probably easiest at this point. But over time as we start to carry more and more electronics, we realize that power_consumption
is broad enough that it should be in the main_product_table
. What should I do now?
Add the field to the main_product_table
. Write a script to loop through the electronics and put the correct value from each type_table
to the main_product_table
. Then drop that column from each type_table
.
Now If I was always using the same GetProductData
class to interact with the database to pull the product info; then if any changes in code now need refactoring, they should be to that Class only.