I'd probably write a function that asserted that each object
implemented the right functions, and threw if something was wrong, and
then call that from each file. Most people would just put that in the
tests, however.

to take that to the next level, you could wrap functions with
functions that checked the argument/return types, and generated run
time errors. the checker could be disabled in production mode.
this approach is known as "design by contract", it's not particularly
popular though.

I am writing a module for this https://github.com/dominictarr/macgyver
with the aim of using it to make assertions about the order, and
eventual occurrence of events, in streams for example.

but in general, simply having unit tests should probably suffice to
make sure your modules stay consistent.



On Mon, Jul 2, 2012 at 3:48 AM, Dave Horton <[email protected]> wrote:
> Since javascript provides no explicit support for the concept of interfaces
> (but, as always, probably a hundred ways to roll your own), what is the node
> best practice or recommendation for defining an interface?
>
> As background, I am building some node modules that will interwork with each
> other, yet be loosely coupled.  And I want to allow others to plug in new
> modules into this mini framework in the future.  So defining an abstract
> interface for some of the different sets of functionality seems to be a good
> way to go.  I have the use of utils.inherit, but I'm not looking for
> inheritence here so that is not the solution I want.  I want to be able to
> define interfaces, and then create objects which declaratively implement one
> or more interfaces.
>
> (I realize this is not a node question, per se, rather more of a generic JS
> question, but I think by pushing forward into the world of more complex
> server-side development node module developers would encounter this issue
> and I would like to be aware of and conform to what bp exist)
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to