Thursday 20 April 2017

How much knowledge does a module needs to have about the project

I am trying to make modules have less knowledge about my other modules it is using. For example, my controller that manages user creation will take a database module and use it to create a user. It will first to parse the details in req, and then pass it to database module, calling a particular function.

registerController.postUser =  function(req, res, next){
    email = req.body.email;
    password = req.body.psw;
    var pswHash = crypto.createHmac('sha256',secret).update(password).digest('hex');
    db.register.createUser(email,pswHash);
}

In this case the controller module knows my db module has a .register.creatuser function. What if I want to change the organization of the database module I will have to come and modify this part of the code too. Do you think this is enough seperation or no? Should I individually pass in functions instead of the whole db module, for example make the above code take one more argument that is the createUser function and use that instead of doing db.register.createUser.



via Nullha

No comments:

Post a Comment