I have a class, lets call it ‘Words’, that reads a file and creates a list of strings.
I then have a class, ‘Items’, that creates a list of ‘description’ objects, each description object needs access to the list from ‘Words’.
Since the ‘Word’ list reads a file, I obviously don’t want to create that list for each ‘description’ object. So what would be the best way of accessing that list?
Should I just create a function getList() from ‘Words’ and pass it to ‘Items’ constructor, then pass it again to each ‘description’? or is there a better way? If I do that, then I would also want to make sure it is only a reference to the list and not a copy since the ‘Words’ list can get huge.
I am relatively new to java and any help would be appreciated.
You need to create a class that pupulate the
Listof String object (singleton), call that singleTon method in constructor of description class to assign reference of list to thedescriptionobject.In description class,