Imagine you're developing an REST API.
You need a method that provides something basic information for the setup of the service, do you think it's a good practice to initialize the service class outside of the constructor? What other options might be better?
public class Controller {
private Service service;
@PostMapping(value="/setup")
public void setup(@RequestBody SetupInfo setupInfo) {
service = new ServiceImpl(setupInfo);
}
@PutMapping(value="/anotherMethod")
public void anotherMethod(@RequestBody Something something) {
marsRover.something(something);
}
}
Aucun commentaire:
Enregistrer un commentaire