• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question regarding fileReader placement  RSS feed

 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question pertains to where should I put my fileReader at? I have three classes, one for main method, one for linked list with inner class node and the last class is contributor. Should I make a new class for the file reader or should I add it to the main method so everytime the application starts it reads in the file and adds the contributors? What are yall's opinion.......


code for file reader will change to insert values into the contributor class......

 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should not be in the main method.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually decided to use two constructors for the contributor class and the constructor without any arguments will read in the file. This is what I need as anytime an instance is created of the contributor class I need to get the saved contributors.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That appears to mean you are creating several objects which would have identical state. Have I got that bit wrong? Is that what you want? If you want a default instance with the details all filled in from the properties file, consider making the class immutable and returning multiple references to the same instance in a getInstance() method.
That is a factory method. Hint: Factory methods usually have to be called before an instance is available and must therefore be marked static.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:That appears to mean you are creating several objects which would have identical state. Have I got that bit wrong? Is that what you want? If you want a default instance with the details all filled in from the properties file, consider making the class immutable and returning multiple references to the same instance in a getInstance() method.
That is a factory method. Hint: Factory methods usually have to be called before an instance is available and must therefore be marked static.



Wow Campbell, you just taught me something new. I will decide to do that......
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Sexton wrote: . . . Wow Campbell, you just taught me something new. I will decide to do that......
Surprising what you pick up every now and again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!