I am going to write an application that reads data from a csv file, and display that data to the user. I intend to apply an MVC design pattern to create this application. A user will interact with this application through a console. Hence the view is a console.
There will be a Main.java that is responsible for :
- Presenting a menu that a user can choose in the console.
- Able to handle event in the console, e.g.: a user choose an option to read two csvfiles and ask the application to display differences between the two csv files.
- Execute appropriate business logic for selected events.
To do this the Main.java will have a Main method that displays menu to a user in a console.
I am considering to make the Main.java as a Controller, because this class is responsible for taking the user input, and figure out what to do with the input. To do this, The Main.java will call a class called FileService.java, which is a service class. FileService.java is responsible for:
- Read a csv file.
- Display the content of the text file sorted according to some rule.
- Display differences content of 2 csv files.
The FileService will parse the csv file using a csv parser, and stores the content of the files on a disk using MapDB. The intention of using MapDB is to allow user read huge file (e.g.: 5 GB), and perform operations to the content of the file. Once the file has been read, Main.java could display the content of the file, or display the differences between the 2 text files, when a user select the option in the console.
The FileService is intended to be the Model part in this application. And, the FileService is completely decoupled from the view and the controller, which is the Main.java.
Does this simple design achieve separation of concern addressed by MVC ?
Response to @tgkprog:
where is the view? if main is the controller and FileService the model/ business part then you need a view class too.
Response : When I built a web application, a view would be, but not limited to, a JSP, or an HTML page. In the context of the CSV file reader application, what would be the equivalent of a HTML or a JSP page ? This is some thing that I am not sure. The menu displayed in the console can be simply achieved inside the main method of the Main.java.
if the files are 5mb then i think a console app will be quite inadequate to display differences unless there are very few?
Response: I could dump the difference in a text file, and let user view the text file. This would be more helpful for them I think. Thank you for pointing this out.