[erlang-questions] How to code against an interface rather than an implementation?

Jesper Louis Andersen <>
Fri Aug 9 18:26:59 CEST 2013


On Fri, Aug 9, 2013 at 9:41 AM, H.C. v. Stockhausen <> wrote:

> I need a DB backend for my application but I'd like to be able to swap
> it out for different DBs if I choose so later on.
>

The key point about swapping out is that it is a *static* property of your
program here. So I would just

-define(db, foo_db_mnesia).

[...]

?db:transaction(fun() -> ...)

and so on. There is little reason to make this harder by making the choice
of the database dynamic at runtime unless you really need it. Tools, like
the dialyzer, will make a best-effort at catching problems, should they
occur.


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130809/e9006fe9/attachment.html>


More information about the erlang-questions mailing list