java - Database Client Design to support different backends -


what usable design patterns use implementing data base client capable of supporting various backends? (e.g. mongodb, or postgres,...)

as simple approach, create interface defines methods crud operations:

interface dbdriver {   void write(string data);   string read();   ... } 

classes implementing interface injected in client class like:

class dbclient() {   public dbclient(dbdriver dbdriver) {     ...   }    //methods write, read, update ...  } 

adapter encapsulate database specific details while exposing common interface.

factory method instantiate correct adapter.

the dao pattern adapter.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -