Approach 3: Dependency Injection

  • Use annotations to indicate that a class can be "injected" into another
  • Spring will pass you an instance of that class in the constructor of a class that depends on it
  • This makes testing easier
  • And also makes it clear what classes depend on which other classes

30 / 31