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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.