How to write loosely coupled classes in node.js
        Posted  
        
            by 
                lortabac
            
        on Programmers
        
        See other posts from Programmers
        
            or by lortabac
        
        
        
        Published on 2012-09-04T17:40:28Z
        Indexed on 
            2012/09/04
            21:50 UTC
        
        
        Read the original article
        Hit count: 298
        
I am trying to understand how to design node.js applications, but it seems there is something I can't grasp about asynchronous programming.
Let's say my application needs to access a database. In a synchronous environment I would implement a data access class with a read() method, returning an associative array.
In node.js, because code is executed asynchronously, this method can't return a value, so, after execution, it will have to "do" something as a side effect. It will then contain at least 1 line of extraneous code which has nothing to do with data access. Multiply this for all methods and all classes and you will very soon have an unmanageable "code soup".
What is the proper way to handle this problem? Am I approaching it the wrong way?
© Programmers or respective owner