Hans Hovan wrote:
If the ProcessorController class contained something like this:
So part of the ProcessorController class would look like this instead:
I think it would make sense since we've linked the interface with its implementation. But it isn't that way. So what is going on here? Any help is appreciated!
If you do that, you've negated the usefulness of programming to an interface instead of an implementation. This design would be far inferior to the other since it's programmed to a specific implementation. What you're seeing is Spring's @Autowire magic in action where it will find a class marked with @Component and inject it into something marked as @Autowired that takes an IProcessor implementation. It can be any IProcessor implementation and not a particular one. This creates a "seam" in your program where you can switch out the implementation with a different one, say for
testing purposes, and the program should still work as expected.