java - Using an interface and dependency injection -
i have program needs read data number of sources. have several objects, each containing list of students , test scores. have class must extract information each object.
the problem must operate through interface. i.e.
public class total{ hashmap<string, integer> results; scoresinterface si; ... void addscores(){ results.putall( si.getscores()); } } public interface scoresinterface{ public hashmap getscores(); } public class scores implements scoresinterface{ hashmap<string, integer> results; ... public hashmap getscores(){ return results; } } i hope code makes sense. total class needs access number of scores objects , collect information.
my question basically, how can let total class know objects of scores class? have thought adding function in total called setsource(scoresinterface a) , passing each new object of scores in. however, seems bit long winded. if there 100 objects.
thanks help
i pass in list<scoresinterface>.
that way use total class iterate through , calculate total.
the type of list implementation (arraylist, linkedlist etc..) you.
Comments
Post a Comment