title: Why do we need Spring framework?
body: <p>Hi I am new to String and is reading the article by Martin Fowler: <a href="http://martinfowler.com/articles/injection.html" rel="noreferrer">http://martinfowler.com/articles/injection.html</a></p>
  
  <p>He gave an example of MovieLister using a MovieFinder for finding movies. In this example, he first provided the code:</p>
  
  <pre><code>class MovieLister...
      private MovieFinder finder;
      public MovieLister() {
          finder = new ColonDelimitedMovieFinder("movies1.txt");
      }
  }
  </code></pre>
  
  <p>He pointed out that you can't give MovieLister to your friend for reuse, unless your friend uses the same MovieFinder implementation and put the movies in the same txt file.</p>
  
  <p>Yes, of course, this is NOT the way you write a component with a hope that someone can reuse it. Instead, as he progressed, you should write:</p>
  
  <pre><code>class MovieLister...
      public MovieLister(MovieFinder finder) {
          this.finder = finder;       
      }
  }
  </code></pre>
  
  <p>Yes, that is better. Now your friend can take over your MovieLister and plug in his own code. To me, the story is complete. I miss the point why you need a Spring framework to inject the dependency. The dependency is injected to MovieLister by your friend's code. Full stop. All the Spring setup is equivalent to simply implement the MovieFinder interface and make such a call:</p>
  
  <pre><code>MovieFinder myMovieFinder = new MyMovieFinderImpl();
  MovieLister myMovieLister = new MovieLister(myMovieFinder);
  </code></pre>
  
  <p>Simple, easy. I know you hard code the creation of the MyMovieFinderImpl instance in your code. But what's the point of moving this to XML but bringing so much other stuff? Since when programmers become so scared of compiling code and prefer changing XML without compiling to get everything done? I am sorry but I think I just miss the point. Every program uses dependency inject, decades ago. But in the old days, dependency is injected by programs using a library, or a DOS command line, or a GUI. Why now we need yet another way as to inject dependency?</p>
  
  <p>Thank you.</p>
  
  <p>Updated:</p>
  
  <p>Well, many of you guys brought annotation up. In my sallow understanding of Spring, I may feel more comfortable using XML rather than annotation. At least there is a central place listing how the dependency is, in a way that is easier to understand. With annotation, no such central place. Instead, just magic happening. Wanna know what is passed in as the parameter? Go figure it out yourself and good luck. Yes, I know there are smart IDE plugins help  navigate the code. But why we make one thing complicated in the first place and celebrate another thing that helps make our life easier? The truth that annotation makes code harder to browse and understand so people create IDE plugins for this is obvious enough that we may create unnecessary things in the first place, isn't it?</p>