Well, we have one main table in the owodc table, let's call it "products" this has an entry for every product. Then, in the same database, we have cd_products, dvd_products, game_products etc. We also have quite a complicated pricing system and charts etc. In a seperate database ("ext_prods") we have abCorpCD, abCorpDVD and abCorpGame tables which hold the product details for the abCorp products. The owodc and abCorp products differ almost completely. Different locations and schemes for the product details, pricing mechanism etc.
I was thinking about somthing like what you suggest with the storage layer but it would have to be a little more I think, to incorperate caching and the different pricing schemes. What do you think of something like this?
abstract class ProductFactory {
public static function get( $type, $id ) {
switch {
case Product::CDWCD: return CD::get( $id, new CDWCDPersist() );
case Product::CDWDVD: return DVD::get( $id, new CDWDVDPersist() );
case Product::CDWGAME: return GAME::get( $id, new CDWGAMEPersist() );
case Product::EUKCD: return CD::get( $id, new EUKCDPersist() );
case Product::EUKDVD: return DVD::get( $id, new EUKDVDPersist() );
case Product::EUKGAME: return GAME::get( $id, new EUKGAMEPersist() );
}
}
}
abstract class Product {
const
CDWCD = 1,
CDWDVD = 2,
CDWGAME = 3,
CDWELEC = 4,
CDWCOSM = 5,
CDWJWLY = 6,
CDWLING = 7,
EUKCD = 10,
EUKDVD = 11,
EUKGAME = 12;
abstract public static function get( $id, ProductPersist $persist );
}
interface ProductPersist {
public static function getProduct( $id );
public static function updateProduct( $params );
}
/**
* This is just done as a stub, in the real world this has stuff in it's methods ;)
*/
class Persist {
public static function get( $cache_key, $classname, $sql, $sql_vars );
// ...
}
class CDWCDPersist extends Persist implements ProductPersist {
public static function getProduct( $id ) {
$sql = "SQL TO GET THE CDWCD PRODUCT OUT OF THE DATABASE";
$var = array( $id );
return self::get( "product:" . Product::CDWCD . ":" . $id, 'CD', $sql, $var );
}
}
Although, the fact that the two different product "classes" (in the broader sense of the word) differ in so many ways is drawing me towards having two almost totally independent branches of the class hierachy. ie.
- = inherits
: = implements
Product
-CDWProduct
--CDWCDProduct : CD
--CDWDVDProduct : DVD
--CDWGAMEProduct : GAME
-EUKProduct
--EUKCDProduct : CD
...
ProductType
-CD
-DVD
-GAME