This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question regarding fileReader placement  RSS feed

 
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......

 
Marshal
Posts: 58395
178
  • 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: 58395
178
  • 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: 58395
178
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!