Jump to content

design pattern gurus help!


alexweber15

Recommended Posts

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! :)

Link to comment
https://forums.phpfreaks.com/topic/124264-design-pattern-gurus-help/
Share on other sites

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.

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  ???

 

:P

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);
    }

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.