In AngularJS application, for one module say "login" functionality can we create multiple services files like logincheck-svc.js and logingo-svc.js And reference both the files in login-ctrl.js file I am asking this question because the services files are becoming large in terms of LOC and Plato report is showing very low maintainability index[due to the complexity in the file]
Asked
Active
Viewed 249 times
0
-
If anything, simply breaking unmaintainable code into several files will **decrease** maintainability even further (because now the mess isn't nicely contained in a single file) – Sergio Tulentsev Jul 15 '15 at 12:15
-
we are working on showcasing the improvements that can be done to the existing angularjs application. The Plato report considers Halstead metrics which says more operators and operands then more complex is the code. So i was thinking why dont i divide the functionality to 2 different services files – Sahana Jul 15 '15 at 12:21
-
I get that. Shuffling code around to satisfy the machine very often does not lead to actual increase in readability, maintainability and other metrics that actually matter. Sometimes a 30-line method should stay a 30-line method instead of being converted to 50 one-line methods. – Sergio Tulentsev Jul 15 '15 at 12:30
-
Regarding the split you proposed: blindly splitting the file in half will not do you any good. However, if you managed to extract logically separate pieces, it'd be a different matter. – Sergio Tulentsev Jul 15 '15 at 12:36
-
Thanks for your input, let me see if we really can separate independent functionalities into different files – Sahana Jul 16 '15 at 06:20
2 Answers
0
As far isolation of concerns you can have as much dependences on your controller as you wish.
angular.module('app.controllers').controller('OneController', [
'$scope',
'OneService',
'TwoServices',
'ThreeServices',
function ($scope, OneService, TwoServices, ThreeServices) {...}]);

Custodio
- 8,594
- 15
- 80
- 115
0
Of course you can, I would even say it is a very good idea from the moment your files become voluminous. :-)
"Divide and conquer"

Mistalis
- 17,793
- 13
- 73
- 97