mardi 27 janvier 2015

How to design database tables for a Factory class?


How can I design database table structure for a class that varies in its core parameters, when it is created by a factory method?


I have a Factory like this:



class ProductFactory
{
public function giveMeProduct()
{
switch ($this->productLine) {
case "A": return new AProduct();
case "B": return new BProduct();
case "C": return new CProduct();
case "D": return new DProduct();
case "E": return new EProduct();
case "F": return new FOptions();

default: return new Product();
}
}
}

$product = (new ProductFactory("A"))->giveMeProduct();


Each product has different parameters. There are some shared, but not many.


So for example once created, each product contains the following variable options:



______stages___pipes___holder___orientation (flags)
| A | x | | | |
| B | | x | x | x |
| C | | | | x |
| D | | x | x | |
| E | | x | | |
etc


So I can either design several tables, one for each product, but I think doing so will be quite wasteful in resources (extra tables, files, connecting tables) for just a few parameters in a small little product options class. Or I can cobble all product options into a single table, which will be sparse, like one above. It will be wasteful but in other ways (table space), although seeing that I don't have many options it may be okay.


In a word, I have 6 classes, each with different options, most of which are not shared among classes.


How do I design a table for this class to persistently store and recover data? What patterns can I use?





Aucun commentaire:

Enregistrer un commentaire