• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where to put Code

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm creating a process that will read an excel file of user accounts that need to be deactivated. I have a class for the Excel File (filePath, fileName, etc.) and a class for Users (userId, userName, termDate).

Where should I put the code that opens the excel file, reads it and creates a map of Users?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably in some kind of driver class. If this were a bigger project, you might create a DAO (data access object), but I think that's overkill in this situation.

Are you using Apache POI? Here is an example of how to use it.
 
Bob Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I'm using POI, I know how to read the file, load the map, etc.

I'm just confused on where to put the code that opens the excel file, reads the contents, loads the contents to the User pojos.

Do I put this code directly in Main(), do I create a method in the ExcelFile object, and and call that method from within main?

Do I create a utility class that does this stuff and call that method from main?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main() method should have at most two or three lines, often just one. I would create a utility class (what I would call a driver class), put a one-line main() in it, calling a method that calls the other methods in other classes. Others would argue that you should have a class with only main() in it that calls a method in a driver class. It depends on the size and reusability of the project.

Either:

or:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic