Using an interface and dependency injection
<p>I have a program that needs to read data from a number of sources. I have several objects, each containing a list of students and their test scores. I then have another class which must extract all the information from each object.</p>

<p>The problem is that I must operate through an interface. i.e.</p>

<pre><code>public class Total{
      HashMap&lt;String, Integer&gt; results; 
      ScoresInterface si;
      ...
      void addScores(){
         results.putAll( si.getScores());
      }

}

public interface ScoresInterface{
       public HashMap getScores();
}

public class Scores implements ScoresInterface{
     HashMap&lt;String, Integer&gt; results;
     ...
     public HashMap getScores(){
            return results;
      }
}
</code></pre>

<p>I hope this code makes sense. The Total class basically needs to access a number of Scores objects and collect all the information.</p>

<p>My question is basically, how can I let the Total class know about all the objects of the scores class? I have thought about adding a function in Total called setSource(ScoresInterface a) and passing each new object of Scores in. However, it seems a bit long winded. What if there are 100 objects.</p>

<p>Thanks for any help</p>
