title: Better practice with Spring MVC: Service with non-fixed dependency
body: <p>I have a requirement of compatibility with a new architecture based in Spring 3.2. The requirement is: a http request will come to a controller with an attribute that defines which kind of object is required. For example ...mycontroller/load?objType='obj1'. </p>
  
  <p>My controller will have this structure:</p>
  
  <pre><code>@Controller
  public class myController{
  
  private ObjectService objectService;
  
  @Autowired
  public setObjectService(ObjectService objectService){
      this.objectService = objectService;
  }
  
  }
  </code></pre>
  
  <p>So after that, I need to check this attribute to decide which service will I use. For example, this case is Obj1Service (method: "load"). All this services are extended from  ObjectService, so: It is a good idea to swap objectService dependency to Obj1Service / Obj2Service in each incoming call? For example: </p>
  
  <pre><code>if(objType.equals("obj1")) this.setObjectService(context.getBean("obj1Service"..))
  if(objType.equals("obj2")) this.setObjectService(context.getBean("obj2Service"..))
  </code></pre>
  
  <p>I know that is not a great design, but we need to integrate this new modules with other system that produces this kind of http requests.
  It is necessary the inheritance because we have very similar behavior in many service's code, but with modifications in internal methods, so part of the behavior will be placed in ObjectService (it is not abstract) and other portion of the code will be placed in it children. Is there another way, more appropriate, to do this? Or you consider that is an acceptable solution? </p>
  
  <p>Thanks!</p>