instead of static methods?
Testabilty for one. Like CreditCardService.charge If it is a static method, testing means you actually lose money everytime you charge But if you use an interface, you can create a mock using Mockito or other mocking frameworks
Your rewritten question actually answers your original one)) Controllers are not static to allow DI. There may be other reasons, but this one is the most obvious one. You can't inject properties in classes (instances of Class<MyController>). For example, if you need to use some MyService in controller, you couldn't use it by simple injection as a static field. The holy grail of spring - dependency injection - would be impossible without object instantiation.
Обсуждают сегодня