[erlang-questions] Mock functions
Joel Reymont
joelr1@REDACTED
Mon Sep 4 19:24:12 CEST 2006
You don't have objects in Erlang but you do have processes. These can
respond to any message you want since messages are standard Erlang
terms (tuples, lists, etc.).
There's nothing preventing you from creating two modules (OTP
gen_serve) that respond to the same set of messages differently. One
implementation is your mock implementation and the other is the real
one.
Just plug in one process instead of the other, depending on the
circumstances, by passing it somewhere as an argument.
On Sep 4, 2006, at 4:45 PM, Arnaud Bailly wrote:
> So the question is: In erlang, how can I provide "virtual" functions ?
> I think the only way would be to "thread" a DB interface record
> containing functions as field into all my business methods. In
> Haskell, I could write a monad and encapsulate all my business logic
> in a DB Monad for abstracting away side-effects on the DB layer. In
> java, I create a reference to a DAO interface that is wired to
> business object at deploy or creation time.
--
http://wagerlabs.com/
More information about the erlang-questions
mailing list