0 Replies - 95 Views - Last Post: 17 December 2013 - 04:12 AM

#1 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

refactoring a service in angular js

Posted 17 December 2013 - 04:12 AM

var myModule = angular.module('myModule', []);
myModule.factory('serviceId', function(name) {

switch(name)
{
case "James"
return "I'm james";

case "Mike"
return "I'm Mike";

case "Jo"
return "I'm Jo"
}

});

In the future if I wanted to add a new case directly I would break OCP. So what would be a good way to refactor this, so that instead of modifying the switch directly, I can add a new case through (javascript).

Thanks

Ray

Is This A Good Question/Topic? 0
  • +

Page 1 of 1