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
Post a Comment