Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Where to put Code  RSS feed

 
Bob Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!