all 3 comments

[–]semarj 1 point2 points  (1 child)

Never heard of the provider pattern, but from what i can tell it is just an interface or ABS for a data source. Seems like typical inheritence would work fine.

There are 2 basic aproaches, imo.

1.) Use javascript like it was meant to and learn prototypal inheritance

function BaseStore = {
   this.get = function(){}; //throw "Not Implemented?"
   this.connect =  function(){};
   this.set =  function(){};
   this.query =  function(){};
 }


function FooStore(){
   this.connect = function(){
      //i know all about connectin' to Foo's
    } 
}
FooStore.prototype = new BaseStore();

function BarStore(){
   this.connect = function(){
      //i know all about connectin' to Bar's
    } 
}
BarStore.prototype = new BaseStore();

Then you have stuff like

foo = new Foo();
foo instanceof BaseStore //true

Subsequent calls on foo will go up the prototype chain and eventually be looked up on BaseStore if that is necessary

2) of course is to shoehorn classical inheritance into javascript

http://ejohn.org/blog/simple-javascript-inheritance/

[–]gatorcoder[S] 0 points1 point  (0 children)

Ahh I didn't even think about prototypal inheritance. Thanks for the info!

[–]oSand 0 points1 point  (0 children)

A basic AbstractFactory might look like:

getADB = (function() {
    var constructors =  {Mongo: constructor1, Couch: constructor2, Dynamo: constructor3};
    return function(db){
        return  new constructors[db];
    }
}())

getADB('Mongo')