alexweber15 Posted September 15, 2008 Share Posted September 15, 2008 looking to create a solid "model" layer for an application.... - initially only mysql is used - we have plans to use xml and json in the very near future - since we're here, might as well make room for any other DBs... Im thinking of going with one big "StorageFactory" with 2 sub-factories being "DBStorage" and "FileStorage"... - Implementing each of the 2 "sub-factories" on their own is kind of straightforwards from what I've been reading and testing.... Is trying to develop a "one-to-end-all" "StorageFactory" as described above a bad idea? Also, one thing thats been killing me is storing data is fine, but what about retrieving it? maybe its a by-product of a well-implemented Factory for storing the data, but it just gives me the chills... someone said to use a REGISTRY pattern but is it really necessary? thanks! Quote Link to comment Share on other sites More sharing options...
corbin Posted September 15, 2008 Share Posted September 15, 2008 I would just use a factory. For example: class HorribleFactoryExample { public function getUserClass() { //return either UserFromFile or UserFromDB } } Then, since FromFile and FromDB would have the same methods, it wouldn't matter to the rest of the application where the data came from. Someone better than I at OOP will probably have a more elegant solution x.x. Quote Link to comment Share on other sites More sharing options...
alexweber15 Posted September 15, 2008 Author Share Posted September 15, 2008 thanks thats a start! but they would have slightly different implementations afaik, like the FromDB would be required to implement standard CRUD functionality... and have some persistence logic somewhere... the FromFile would mainly be "CR"... (again a guess), but the XML and JSON data would probably only be required to feed other services such as SOAP or a RIA view layer, so really I'd just need to retrieve a select subset of the data and not necessarily have to manipulate it much like a database, assuming it would just be a cached file or something generated on request or something... dunno ??? Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted September 16, 2008 Share Posted September 16, 2008 Here would be my basic singleton factory pattern: class Factory { protected static $_instance; private function __construct() {} public static function getInstance() { if(self::$_instance === false) { self::$_instance = new self(); } return self::$_instance; } public static function create($object, $id=null) { return new $object($id); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.